Read Roman Numerals

Roman numbers are written with letters, and each letter has its own value. The function roman_to_int receives a Roman numeral string s. Add the symbol values, but subtract a smaller symbol when it appears before a larger one: for example, IV is 4 and IX is 9. Return the regular integer value.

Примеры

Ввод
"III"
Вывод
3
Ввод
"LVIII"
Вывод
58
Ввод
"MCMXCIV"
Вывод
1994

Нужно реализовать

def roman_to_int(s):

Теги

stringshashmapmath
PostgreSQLv16

Qui apparirà il risultato dell'esecuzione del codice

Visible tests
1
Input
"III"
Expected3
2
Input
"LVIII"
Expected58
3
Input
"MCMXCIV"
Expected1994
4
Input
"IV"
Expected4
5
Input
"IX"
Expected9
6
Input
"MMXXIV"
Expected2024
Focus radio
Paused · SomaFM · Fluid