Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- res = 0
- c = False
- CONV_TABLE = ((1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'),
- (100, 'C'), (90, 'XC'), (50, 'L'), (40, 'XL'),
- (10, 'X'), (9, 'IX'), (5, 'V'), (4, 'IV'), (1, 'I'))
- def roman_to_arab(txt):
- txt = txt.upper()
- ret = 0
- for arab, roman in CONV_TABLE:
- while txt.startswith( roman ):
- ret += arab
- txt = txt[ len( roman ): ]
- return ret
- x = [i for i in input()]
- for i in range(len(x)):
- if c:
- c = False
- continue
- elif i == len(x):
- res += roman_to_arab(x[i])
- if x[i] == 'I':
- if x[i + 1] == 'V':
- c = True
- res += 4
- elif x[i + 1] == 'X':
- c = True
- res += 9
- elif x[i] == 'X':
- if x[i + 1] == 'L':
- res += 40
- c = True
- elif x[i + 1] == 'C':
- res += 90
- c = True
- elif x[i] == 'C':
- if x[i + 1] == 'D':
- res += 400
- c = True
- elif x[i + 1] == 'M':
- res += 900
- c = True
- else:
- res += roman_to_arab(x[i])
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement