#C2236. Roman Numerals to Integer

    ID: 45530 Type: Default 1000ms 256MiB

Roman Numerals to Integer

Roman Numerals to Integer

You are given a string representing a Roman numeral. Your task is to convert this numeral to its integer equivalent.

The Roman numeral system uses the following symbols:

$$ I = 1,\ V = 5,\ X = 10,\ L = 50,\ C = 100,\ D = 500,\ M = 1000 $$

When a smaller numeral appears before a larger numeral, it is subtracted. Otherwise, the numeral values are added. For example, MCMXCIV is interpreted as M (1000) + CM (900) + XC (90) + IV (4) = 1994.

Write a program that reads a Roman numeral from standard input and prints its integer value to standard output.

inputFormat

The input consists of a single line containing a valid Roman numeral string. You can assume the numeral is in its standard form and its value is between 1 and 3999.

Example:

MCMXCIV

outputFormat

The output is a single integer representing the numeric value of the given Roman numeral.

Example:

1994
## sample
MCMXCIV
1994