#P4711. Calculate Relative Molecular Mass
Calculate Relative Molecular Mass
Calculate Relative Molecular Mass
In this problem, you are given the formula of a chemical substance and you need to calculate its relative molecular mass.
For a chemical formula, the molecular mass (M) is given by the formula: (M = \sum_{i} a_i m_i), where (a_i) is the number of atoms of element (i) and (m_i) is the atomic mass of element (i).
For example, for H2O, we have (M = 2 \times 1 + 1 \times 16 = 18). Help Little F solve his problem!
inputFormat
The input consists of a single line containing the chemical formula as a string. The formula is composed of element symbols and their counts. An element symbol starts with an uppercase letter and may be followed by a lowercase letter. The count of atoms is given immediately after the element symbol. If the count is omitted, it is assumed to be 1. For example, the formula for water is given as: H2O
outputFormat
Output a single integer representing the relative molecular mass of the given chemical formula. For the sample above, the output should be 18
.
sample
H2O
18