Chemistry
Time limit2sMemory limit1024 MB
Given a chemical formula with C, H, N, O and counts, the task is to print the total molar mass using fixed atomic weights.
- Level
Easy2 of 10
- Topics
- String, Implementation, Simulation
- Solved
- No attempts yet
Problem
Your task is to compute the mass of a molecule given by its chemical formula. The formula is a list of the elements in the molecule. The notation means that element is repeated times. The mass of a molecule is the sum of the weights of all its elements.
The input file has one line containing the formula. The formula is at most 20 characters long. It consists of the letters C, H, N, O and the digits 1 to 9. A digit always follows a letter.
Output
Print one number to the output file: the mass of the molecule.