2012 Canadian Computing Competition, Stage 1

Problem S2: Aromatic Numbers

This question involves calculating the value of aromatic numbers which are a combination of Arabic digits and Roman numerals.

An aromatic number is of the form ARARAR...AR, where each A is an Arabic digit, and each R is a Roman numeral. Each pair AR contributes a value described below, and by adding or subtracting these values together we get the value of the entire aromatic number.

An Arabic digit A, can be 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. A Roman numeral R is one of the seven letters I, V, X, L, C, D, or M. Each Roman numeral has a base value:

SymbolIVXLCD M
Base value151050100 5001000

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'R' with R' 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×1000 + 1×500 + 2*100 = 3700 and 3X2I4X has the value 3×10 - 2×1 + 4×10 = 68.

Write a program that computes the values of aromatic numbers.

Input Format

The input is a valid aromatic number consisting of between 2 and 20 symbols.

Output Format

The output is the decimal value of the given aromatic number.

Sample Input 1

3M1D2C

Sample Output 1

3700

Sample Input 2

2I3I2X9V1X

Sample Output 2

-16

All Submissions
Best Solutions


Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Feb 29, 2012

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, TEXT, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

In java if you use the .split() method on the input the first index will be a "" value. Is this supposed to happen?


This is in fact supposed to happen in Java 7. Splitting a string by "" (or generally anything that would produce an empty first part, such as splitting "ananas" by "a") will result in an empty string as the first element.

This is changed in Java 8.

Please take into account the extra first element, as the judge is on Java 7. Alternatively, use "abc".split("(?!^)"), which will not produce an initial character on either Java 7 or 8 (but breaks on unicode input).

Why not copy the problem description from the CCC website?
The problem description is here : http://cemc.uwaterloo.ca/contests/computing/2012/stage1/seniorEn.pdf

Every problem description is missing...

Why?

It seems like all the problem-specific content got accidentally deleted. I'm restoring from a backup now. Please stand by, there is a huge amount of test data so it may take a few hours.

EDIT: Fixed.

My program compiles perfectly on my computer. It is not compiling here...

Problem codes are case-sensitive.