-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patha013.py
More file actions
59 lines (51 loc) · 1.23 KB
/
a013.py
File metadata and controls
59 lines (51 loc) · 1.23 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 2 03:04:41 2019
@author: sam0225
"""
def romanToInt(s):
ROMANSdict = {'M': 1000,
'D': 500,
'C': 100,
'L': 50,
'X': 10,
'V': 5,
'I': 1}
sum = 0
for i in range(len(s) - 1):
if ROMANSdict[s[i]] < ROMANSdict[s[i + 1]]:
sum -= ROMANSdict[s[i]]
else:
sum += ROMANSdict[s[i]]
return sum + ROMANSdict[s[-1]]
def roman(number):
ROMANS = (('M', 1000),
('CM', 900),
('D', 500),
('CD', 400),
('C', 100),
('XC', 90),
('L', 50),
('XL', 40),
('X', 10),
('IX', 9),
('V', 5),
('IV', 4),
('I', 1))
s = ''
for roman, value in ROMANS:
while number >= value:
number -= value
s += roman
return s
while True:
try:
a, b = input().split()
answer = roman(abs(romanToInt(a) - romanToInt(b)))
if answer == '':
print('ZERO')
else:
print(answer)
except:
break