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
Idħol biex tara l-istorja tas-sottomissjonijiet
IdħolIdħol biex tuża l-Mentor tal-AI
IdħolVisible tests
1
Input
"III"Expected
32
Input
"LVIII"Expected
583
Input
"MCMXCIV"Expected
19944
Input
"IV"Expected
45
Input
"IX"Expected
96
Input
"MMXXIV"Expected
2024Focus radio
Paused · SomaFM · Fluid