Roman Number Parser
Roman numerals may look unusual, but they follow a small set of clear rules. Given a string s containing a Roman numeral, return its value as a regular integer. Account for both normal addition and subtractive pairs such as IV, IX, XL, XC, CD, and CM.
Примеры
Ввод
"III"Вывод
3Ввод
"IV"Вывод
4Ввод
"IX"Вывод
9Нужно реализовать
def roman_to_int(s):
Теги
stringshashmapmath
Prihláste sa, aby ste videli históriu odoslaní
Prihlásiť saPrihláste sa, aby ste mohli používať AI mentora
Prihlásiť saVisible tests
1
Input
"III"Expected
32
Input
"IV"Expected
43
Input
"IX"Expected
94
Input
"LVIII"Expected
585
Input
"MCMXCIV"Expected
19946
Input
"MMXXVI"Expected
2026Focus radio
Paused · SomaFM · Fluid