roman = {'I' : 1,'IV' : 4,'V' : 5,'VX' : 9,
'X' : 10,'XL' : 40,'L' : 50,'XC' : 90,
'C' : 100,'CD' : 400,'D' : 500,'CM' : 900,
'M' : 1000}
def num_roman(num = 0, roman = roman ):if num == 0:return 'ZERO'key_array = list( roman.keys() )value_array = list( roman.values() )string = ''key_array.reverse()value_array.reverse()for i in range( 13 ):while value_array[i] <= num:num -= value_array[i]string += key_array[i]return string
def roman_num(string = '', roman = roman ):if string == '' or string == None:return 0key_array = list( roman.keys() )value_array = list( roman.values() )num = 0x = 0y = 2while True:if x >= len(string) or y > len(string):if y == x + 2:y -= 1continuereturn numif string[x:y] in key_array:num += roman[key_array[key_array.index(string[x:y])]]x = y + 0y = x + 2continuey = x + 1while True:input_ = input()if input_ == '#':breaknums = list( map( roman_num, input_.split() ) )nums.sort()print( num_roman( abs( nums[1] - nums[0] ) ) )
沒事,我 IX 打成 VX