当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2695:Molecular Weight Calculator

题目描述
Even though not good at memorizing, Alex is fond of Chemistry. When solving problems, he always needs to calculate the
molecular weight and quantity of each kind of elements. Lazy Alex hates that and turns to you for help.

Your task is:
Given a chemical formula, calculate its molecular weight and quantity of each kind of elements.

The atom is represented by either a single capital letter or a capital letter and a lower case letter. E.g. C, Ca, H, O. Formulas
may contain brackets: '(',')', which is always followed by the quantity of that atomic mission. The number after an atom or a
bracket represents the quantity of that atomic mission. E.g. CH4, CaCO3, Fe(SCN)3. Brackets may be nested.
输入解释
The input consists of multiple test cases. The first line of input contains an integer T, which is the number of test cases.

Each test case is on several lines. The first line contains an integer, N, indicating the quantity of known elements.
Each of the following n lines is consisting of a element description, start with a element name and followed by the weight
W (floating point number), separated by a space.
The (n+1)-th line consists an integer M, indicating the quantity of formulas.
Each of the following M lines is consisting of a formula.

[Technical Specification]
1.T is an integer, and T <=10.
2.N is an integer, and 1 <= N <= 200.
3.W is a floating point number with two fractional digits, and 1 <= W <= 400.
4.M is an integer, and 1 <= M <= 100.
5.Numbers in the formula is always in the range of [2,9] inclusive.
6.The formula?s length does not exceed 500.
7.There's no blank line between two test cases.
输出解释
For each formula in each test case, print a single line as the format below.
Format:
Weight Element[quantity] Element[quantity] Element[quantity] ...
e.g. 44.00 C[1] O[2]
The element is ordered as they were in the input. Display all the elements except for those not in the formula. The weight is
rounded to two fractional digits. Notice that the answer may be very large.
There's no whitespace at the end of each line.
输入样例
1 
7 
H 1.00 
C 12.00 
O 16.00 
N 14.00 
S 32.00 
Ca 40.00 
Fe 56.00 
4 
CO2 
CH4 
CaCO3 
Fe(SCN)3 
输出样例
44.00 C[1] O[2] 
16.00 H[4] C[1] 
100.00 C[1] O[3] Ca[1] 
230.00 C[3] N[3] S[3] Fe[1] 
来自杭电HDUOJ的附加信息
Recommend yifenfei

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-2695

最后修改于 2020-10-25T22:56:00+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
60000/20000MS(Java/Others) 32768/32768K(Java/Others)