2 人解决,2 人已尝试。
2 份提交通过,共有 10 份提交。
8.4 EMB 奖励。
单点时限: 1.0 sec
内存限制: 256 MB
You have landed a lucrative contract with Amalgamated Chemical Manufacturing (ACM), to help their chemists with stoichiometry. Stoichiometry is the calculation of reactants and products in chemical reactions, based on the law of conservation of mass, which states that the total mass of the reactants equals the total mass of the products.
The relations among quantities of reactants and products typically form a ratio of positive integers. If the amounts of the separate reactants are known, then the amount of the product can be calculated, and vice-versa. The relationship of
reactants to products can be described using a soichiometric equation such as:
which can be read as: “One molecule of
will fill in the blanks to produce a balanced equation. For example, the above equation could be balanced as follows:
An equation is input in the form of a sequence of
where +1
or -1
, with a sign of +1
indicating that this molecule appears on the left of the
equation, and -1
indicating that it appears on the right. Fe 2
indicates that the molecule contains two atoms of the element Fe (iron). There will be no more than 10 unique elements in a single equation.
Note that an element may be repeated in a given line of input, as in +1 6 C 1 H 5 C 1 O 1 O 1 H 1
which specifies that at least one molecule of
Input ends with a line of the form 0 0
.
The program must output the numbers
+1 2 H 2 O 1 +1 2 C 1 O 2 -1 1 O 2 -1 3 C 6 H 12 O 6 0 0
6 6 6 1
+1 5 Be 2 C 1 O 3 O 2 H 2 +1 3 Ac 1 O 1 H 1 -1 4 Be 4 O 1 Ac 6 O 6 -1 2 H 2 O 1 -1 2 C 1 O 2 0 0
2 6 1 5 2