#K88987. Roman Numerals to Integer
Roman Numerals to Integer
Roman Numerals to Integer
Given a Roman numeral, convert it to an integer.
Roman numerals are represented by seven different symbols: I, V, X, L, C, D, and M. For example, the numeral MCMXCIV
corresponds to the integer 1994
.
The conversion uses the standard rules: if a numeral appears before one of higher value, it is subtracted, otherwise it is added. Formally, if we denote the integer value of a Roman symbol by \( v(s) \), then the total is computed as \( total = \sum_{i=1}^{n} \Delta_i \) where \( \Delta_i = v(s_i) \) if \( v(s_i) \ge v(s_{i+1}) \), and \( \Delta_i = -v(s_i) \) otherwise.
Read the Roman numeral from standard input and write the resulting integer to standard output.
inputFormat
A single line containing a Roman numeral string. The input is provided via stdin.
outputFormat
Print the integer representation of the Roman numeral to stdout.## sample
III
3