[문제 요약] 분자식을 입력으로 받아 이 분자식의 질량을 구하는 문제.
원소는 C , H , O , N 만 입력되고 각 원소의 질량은
6×(12.01 g/mol) + 6×(1.008 g/mol) + 1×(16.00 g/mol).입력은 80 자를 넘지 않고 원소가 1 개이면 생략하고 원소의 갯수는 2 이상 80 이하이다. 출력은 소수 네 자리에서 반올림하여 세자리까지 출력 한다.
When an organic compound is given as a molecular formula, Dr. CHON wants to find its molar mass. A molecular formula, such as C3H4O3, identifies each constituent element by its chemical symbol and indicates the number of atoms of each element found in each discrete molecule of that compound. If a molecule contains more than one atom of a particular element, this quantity is indicated using a subscript after the chemical symbol.
In this problem, we assume that the molecular formula is represented by only four elements, ‘C’ (Carbon), ‘H’ (Hydrogen), ‘O’ (Oxygen), and ‘N’ (Nitrogen) without parentheses.
The following table shows that the standard atomic weights for ‘C’, ‘H’, ‘O’, and ‘N’.
Atomic Name | Carbon | Hydrogen | Oxygen | Nitrogen |
Standard Atomic Weight | 12.01 g/mol | 1.008 g/mol | 16.00 g/mol | 14.01 g/mol |
For example, the molar mass of a molecular formula C6H5OH is 94.108 g/mol which is computed by 6×(12.01 g/mol) + 6×(1.008 g/mol) + 1×(16.00 g/mol). Given a molecular formula, write a program to compute the molar mass of the formula.
입력 C 출력 12.010 입력 C6H5OH 출력 94.108 입력 NH2CH2COOH 출력 75.070 입력 C12H22O11 출력 342.296
출처: The 31th Annual ACM Programming Contest ASIA Regional - Seoul problem A