http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11342 Problem description |
The chemical formula of a molecule M describes its atomic make-up. Chemical formulas obey the following grammar: M := G | M G G := S | S C S := A | '(' M ')' C := T | N E E := D | D E T := '2' | ... | '9' N := '1' | ... | '9' D := '0' | .. | '9' A := U | U L | U L L U := 'A' | .. | 'Z' L := 'a' | .. | 'z' The count C represents a multiplier for the subgroup S that precedes it. For example, H2O has two H (hydrogen) and one O (oxygen) atoms, and (AlC2)3Na4 contains 3 Al (aluminum), 6 C (carbon) and 4 Na (sodium) atoms. |
Input |
The input will contain data for one or more test cases. For each test case, there will be one line of input, containing a valid chemical formula. Each line will have no more than 100 characters. |
Output |
For each line of input there will be one line of output which is the atomic decomposition of the chemical in the form of a sum as shown in the sample output. The atoms are listed in lexicographical order, and a count of 1 is implied and not explicitly written. There are no blank spaces in the output. All of the counts in the correct output will be representable in 32-bit signed integers. |
Sample Input |
H2O (AlC2)3Na4 |
Sample Output |
2H+O 3Al+6C+4Na |
Problem Source |
2012 Rocky Mountain Regional Contest
题意:按字典序升序输出所有元素 思路:一道恶心的模拟题啊,暴力模拟即可,弄了好久啊,一开始是全部算出来在进行叠加,但是超时了,于是就每次计算完一个元素后都放进去,终于过了,0ms
|
HUNNU11342:Chemistry(模拟)
最新推荐文章于 2017-12-27 16:01:36 发布