1322. Read a Roman Numeral
Print the value of a Roman numeral.
I 1 V 5 X 10 L 50 C 100 D 500 M 1000
Symbols normally run from largest to smallest and simply add up. The exception
is the subtractive form, where a smaller symbol placed BEFORE a larger one is
subtracted instead: IV is 4 and IX is 9, XL is 40, CM is 900.
There is no need to recognise those pairs by name. One rule covers every case:
if this symbol is worth less than the NEXT one, subtract it
otherwise add it
The last symbol has no next one, so it is always added.
That rule is shorter than the list of special pairs and it cannot miss one. A
solution that hard-codes the six pairs reads correctly until a numeral combines
them, which is why MCMXCIV and CDXLIV are both in the tests.
Constraints - The numeral is a valid Roman numeral from 1 to 3999. - Only the characters `I`, `V`, `X`, `L`, `C`, `D` and `M` appear.
Input
One line containing the Roman numeral, in capitals.
Output
Print its value as an integer.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.