#P4711. 「化学」相对分子质量
「化学」相对分子质量
Description
When doing chemistry problems, Xiao F always miscalculates the relative molecular mass, which makes him very distressed.
Xiao F came to you for help. Please compute the relative molecular mass of the given substance.
If you have not studied the related content, that is fine. You can understand what is required from the samples and the hints.
Input Format
Input consists of one line: a string of length without spaces, representing the chemical formula of the given substance.
The chemical formula includes only the following:
- Elements: such as
Au(gold),Hf(hafnium). All occurring elements and their relative atomic masses are given in the appendix. - Subscript
_{}: indicates the count of some atom, ion, or group. For example,H_{2}Omeans (water), andC_{60}means (buckminsterfullerene). - Parentheses
(): indicate a group, and a subscript applies to the content inside the group. For example,Ca(OH)_{2}means (slaked lime). - Hydrate
~: for example,CuSO_{4}~5H_{2}Omeans (chalcanthite). If there is a number before water, it is guaranteed to be a positive integer greater than . If this part is omitted, it defaults to . In the example above, the5indicates the number of water molecules.
Formally, the chemical formula you process satisfies the following rules:
Molecule
~CountH_{2}O
The count or the hydrate part may be omitted.
For the molecule, it satisfies:
Part
_{Count}Part_{Count}... Part_{Count}
The count may be omitted.
For each “Part” (atom, group, ion, etc.), it satisfies:
Element
or
(Element_{Count}Element_{Count}... Element_{Count})
The count may be omitted.
Please note that chemical formulas satisfying the above conditions will not contain nested parentheses. The number referred to as “Count” above does not exceed .
Output Format
Output one line containing either an integer or a real number whose fractional part is .5, which is your computed result.
It is guaranteed that the result does not exceed .
Au
197
HfO_{2}
210.5
Ca(OH)_{2}
74
CuSO_{4}~5H_{2}O
250
KAl(SO_{4})_{2}~12H_{2}O
474
Hint
Sample explanations
Gold .
Hafnium dioxide .
Calcium hydroxide (slaked lime) .
Copper(II) sulfate pentahydrate (chalcanthite) $\text{CuSO}_4 \cdot 5\text{H}_2\text{O}: 64 + 32 + 16 \times 4 + 5 \times (1 \times 2 + 16) = 250$.
Potassium aluminum sulfate dodecahydrate (alum) (Indeed, is correct.).
Appendix: Possible relative atomic masses
| 元素 | 相对原子质量 |
|---|---|
Tips
If you have not studied the related content, the following may help:
zcy teaches you how to compute relative molecular mass
- Each element starts with an uppercase letter.
- To compute the molecular mass, multiply the number of occurrences of each atom by its relative atomic mass and sum them up.
- ~( ) is equivalent to addition.
- A subscript is equivalent to multiplication.
Translated by ChatGPT 5
京公网安备 11011102002149号