Read Roman Numerals
Roman numerals appear in dates, book chapters, and numbering systems, but programs usually need regular integers. Given a Roman numeral string s, return its integer value. If a smaller symbol comes before a larger one, subtract it instead of adding it.
Примеры
Ввод
"III"Вывод
3Ввод
"LVIII"Вывод
58Ввод
"MCMXCIV"Вывод
1994Нужно реализовать
def roman_to_int(s: str) -> int:
Теги
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
"LVIIILVIII"Expected
100Focus radio
Paused · SomaFM · Fluid