Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
124067 | 柯轶炜 | 相对分子质量 | Python3 | Accepted | 38 MS | 3792 KB | 631 | 2025-07-10 22:05:05 |
element_weights = {'H':1, 'C':12, 'N':14, 'O':16, 'F':19, 'P':31, 'S':32, 'K':39} def calculate_molecular_weight(formula): total = 0 i = 0 n = len(formula) while i < n: element = formula[i] i += 1 # 获取数字部分 num_str = '' while i < n and formula[i].isdigit(): num_str += formula[i] i += 1 count = int(num_str) if num_str else 1 total += element_weights[element] * count return total n = int(input()) for _ in range(n): formula = input().strip() print(calculate_molecular_weight(formula))