CCC '12 S2 - Aromatic Numbers
The value of a pair \(AR\) is \(A\) times the base value of \(R\) . Normally, you add up the values of the pairs to get the overall value. However, wherever there are consecutive symbols \(ARA^{\prime}R^{\prime}\) with \(R^{\prime}\) having a strictly bigger base value than \(R\) , the value of pair \(AR\) must be subtracted from the total, instead of being added .
For example, the number \(3M1D2C\) has the value \(3 \times 1000 + 1 \times 500 + 2 \times 100 = 3700\) and \(3X2I4X\) has the value \(3 \times 10 - 2 \times 1 + 4 \times 10 = 68\) .
Write a program that computes the values of aromatic numbers.
Input Specification
The input is a valid aromatic number consisting of between \(2\) and \(20\) symbols.
Output Specification
The output is the decimal value of the given aromatic number.
Sample Input 1
3M1D2COutput for Sample Input 1
3700Sample Input 2
2I3I2X9V1XOutput for Sample Input 2
-16
Comments