-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha013.py
More file actions
36 lines (31 loc) · 749 Bytes
/
a013.py
File metadata and controls
36 lines (31 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
R2I = {
'I': 1, 'V': 5, 'X': 10, 'L': 50,
'C': 100, 'D': 500, 'M': 1000
}
I2R = [
(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 RtoI(s):
total = 0
last = 0
for w in s[::-1]:
v = R2I[w]
total += v if v >= last else -v
last = v
return total
for s in sys.stdin.readlines()[:-1]:
a, b = s.split()
diff = abs(RtoI(a) - RtoI(b))
if diff == 0:
print("ZERO")
else:
r = ""
for v, w in I2R:
while diff >= v:
r += w
diff -= v
print(r)