Roman to Integer
easy⏱ 15 mintypescriptchallengesproblem-solving-basic-
Sample case — your program reads stdin and prints to stdout.
Convert a Roman numeral string to an integer.
I=1, V=5, X=10, L=50, C=100, D=500, M=1000
If smaller value before larger, subtract (IV=4). Otherwise add.
Example: 'MCMXCIV' → 1994 (M=1000 + CM=900 + XC=90 + IV=4)
Input format
A single line containing a Roman numeral string.
Output format
The integer value.
Constraints
1 ≤ s.length ≤ 15, valid Roman numeral in range [1, 3999]