## TLE '16 Contest 1 P3 - Joey and Chemistry

View as PDF

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem types

jlsajfj has been goofing off in his Science 10 class, so he has no idea what complete combustion is! Not wanting to disappoint his teacher, who thinks jlsajfj could do better in the class if he tried, jlsajfj has decided to bother you into doing his homework.

The homework sheet involves balancing hundreds of complete combustion chemical equations. In his homework, only three types of atoms (elements) are involved:

• Carbon (represented by )
• Hydrogen (represented by )
• and Oxygen (represented by )

The general form of such an equation looks like this:

can be any combination of carbon, hydrogen, or oxygen.

In order for the chemical equation to be balanced, the number of atoms of each element (, , and ) must be equal on both sides of the arrow, since atoms cannot be created or destroyed during the reaction. This can be done by setting , , , and to some positive integer value, signifying the number of copies of the substance. A subscript in front of an element signifies the amount of that element in the substance. In the input and output, a subscript will simply be an integer after an element. If there is no subscript in front of an element, there is only one of it.

For example, (2CH3OH in input/output format) contains 2 carbon atoms, 8 hydrogen atoms, and 2 oxygen atoms.

Can you help jlsajfj finish his homework?

#### Input Specification

The first and only line of input will contain a single string, . It is guaranteed that will not begin with a number and will only contain numbers, C, H, and O.

The total amount of each element in will not be greater than .

#### Output Specification

On a single line, output the balanced chemical equation in the form of aR + bO2 -> cCO2 + dH2O, where , , , and are in lowest terms and cause the equation to be balanced, and is the exact copy of what was given in the input.

If it is not possible to balance the equation, simply output Impossible.

#### Sample Input 1

CH3CH2CH3

#### Sample Output 1

1CH3CH2CH3 + 5O2 -> 3CO2 + 4H2O

#### Sample Input 2

CH3OH

#### Sample Output 2

2CH3OH + 3O2 -> 2CO2 + 4H2O

#### Sample Input 3

H2O

#### Sample Output 3

Impossible

• commented on Sept. 22, 2016, 8:41 a.m.

This might be my favourite question yet

• commented on Sept. 22, 2016, 10:46 a.m.

no

• commented on Sept. 21, 2016, 7:24 p.m.

can you use 0 of an element?

• commented on Sept. 21, 2016, 7:40 p.m.

"a, b, c, and d to some positive integer value"

• commented on Sept. 21, 2016, 5:53 p.m.

you say R cannot begin with a number yet you say 2CH3OH in the sample input

• commented on Sept. 21, 2016, 5:55 p.m.

2CH3OH is not in any sample input.

• commented on Sept. 21, 2016, 3:10 p.m.

A little wrong in this problem and I don't have enough time to solve problem P4, P5 and P6. So sad :(

• commented on Sept. 21, 2016, 2:38 p.m.

On a single line, output the balanced chemical equation in the form of aR + bO2 -> cCO2 + dH2O, where aa, bb, cc, and dd are in lowest terms and cause the equation to be balanced, and RR is the exact copy of what was given in the input. For example, 2CH3OH2CH3OH (2CH3OH in input/output) contains 2 carbon atoms, 8 hydrogen atoms, and 2 oxygen atoms. If R is 2CH3OH then how to print output?

1. 2CH3OH + 3O2 -> 2CO2 + 4H2O
2. 12CH3OH + 3O2 -> 2CO2 + 4H2O ( aR + bO2 -> cCO2 + dH2O, a = 1, R = 2CH3OH ) 1 or 2 ???
• commented on Sept. 21, 2016, 2:41 p.m.

It is guaranteed that R will not begin with a number.

• commented on Sept. 21, 2016, 1:56 p.m.

Can R is CH3(CH2)3(OH)6 ???

• commented on Sept. 21, 2016, 1:57 p.m.

No, there are no brackets in R.