s =[
['I', 1],
['IV', 4],
['V', 5],
['IX', 9],
['X', 10],
['XL', 40],
['L', 50],
['XC', 90],
['C', 100],
['CD', 400],
['D', 500],
['CM', 900],
['M', 1000]
]
# 單一個羅馬字元回傳數值 ,像是輸入"I"會回傳 1
def find(string):
for i in s:
a,b = i
if(string==a):
return b
# 單一個數字回傳羅馬字元 ,像是輸入 1 會回傳"I"
def find01(value):
for i in s:
a,b = i
if(value==b):
return a
# 羅馬文字轉數字
def roman_to_value(roman):
roman = [find(i) for i in roman]
for i in range(0, len(roman) ):
if(i!=(len(roman)-1)):
if(roman[i]<roman[i+1]):
roman[i]=roman[i]*-1
new_roman = 0
for i in roman:
new_roman+=i
return new_roman
# 數字轉羅馬文字
def value_to_roman(value):
if value==0 :
return "ZERO"
new_string = ''
for a,b in s[::-1]:
while value>=b:
value-=b
new_string+=a
if value==0 :
break
return new_string
import sys
for v in sys.stdin:
if v=='#\n' :
break
in_1,in_2 = v.split('\n')[0].split(' ')
result = abs( roman_to_value(in_2) - roman_to_value(in_1) )
result = value_to_roman(result)
print(result)