Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def romanToInt(s):
- result = 0
- roman = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
- i = 0
- while i < len(s) - 1:
- if roman[s[i + 1]] > roman[s[i]]:
- result += roman[s[i + 1]] - roman[s[i]]
- i += 2
- else:
- result += roman[s[i]]
- i += 1
- if i < len(s):
- result += roman[s[len(s) - 1]]
- return result
- s = input()
- print(romanToInt(s))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement