summaryrefslogtreecommitdiffstats
path: root/Main/Python/2012/S2.py
blob: 2790998301b6b842059fd04e8696ee722f4d7d62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
n = input()

roman = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}

total = 0

for i in range(0, len(n), 2):
    A, R = int(n[i]), roman[n[i + 1]]
    if i < len(n)-2:
        nR = roman[n[i + 3]]
    else:
        nR = 0
    if nR > R:
        total -= A * R
    else:
        total += A * R


print(total)