Converting Romans
Time limit1sMemory limit1024 MB
Convert each Roman numeral string to its integer value, where any digit left of a larger digit is subtracted.
- Level
Easy3 of 10
- Topics
- String, Simulation
- Solved
- No attempts yet
Problem
Roman numerals are a numeral system that originated in ancient Rome and was widely used across Europe into the Late Middle Ages. Instead of the Arabic digits most of us use today, it writes numbers with combinations of Latin letters, each with a fixed integer value. Over the years many different letters were used, which often caused confusion. The modern style uses only these seven:
A common misunderstanding is that Roman numerals use a universal subtractive syntax. In a subtractive syntax, a lower digit written before a larger digit is subtracted from the larger digit. 4 can be written as IIII or IV . The Romans only really used subtractive syntax for smaller numbers. For larger numbers they largely avoided it, for clarity. For example, can be written LDVLIV, XDIX, VDIV or ID, while older sources most likely would use CDXCIX. Ain't Roman numbers fun?
For the purposes of this problem, we subtract any digit written to the left of a larger digit, even if they are not directly adjacent.
Input
The input starts with an integer . Then follow lines, each containing up to Roman digits. The total number of Roman digits in the input is at most .
Output
Output the corresponding Arabic numbers, one number per line.