#C6598. Roman Numerals to Integer

    ID: 50375 Type: Default 1000ms 256MiB

Roman Numerals to Integer

Roman Numerals to Integer

You are given a Roman numeral as a string. Your task is to convert it to its integer value. The conversion follows these rules:

  • The symbols I, V, X, L, C, D, and M represent the values \(I=1\), \(V=5\), \(X=10\), \(L=50\), \(C=100\), \(D=500\) and \(M=1000\) respectively.
  • If a smaller value precedes a larger value, it is subtracted. Otherwise, the values are added.

For example, the input "MCMXCIV" should return 1994 because \(M + (CM) + (XC) + IV = 1000 + 900 + 90 + 4\).

This is a common problem in coding competitions and tests your understanding of iteration and condition-based logic.

inputFormat

The input consists of a single line containing a valid Roman numeral string. Read the input from stdin.

outputFormat

Output a single integer which is the conversion result of the Roman numeral to an integer. Print the result to stdout.

## sample
III
3

</p>