Read a Roman numeral · Compiler

Read a Roman numeral

Convert a valid Roman numeral to decimal using I = 1, V = 5, X = 10, L = 50, C = 100, D = 500 and M = 1000. Subtract a symbol's value when the next symbol has a larger value. Add it in all other cases, including the last symbol.

Input
One uppercase Roman numeral in standard form representing an integer from 1 to 3999.
Output
Print its value as a decimal integer.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…