inputList = []while True:Input = input()if Input == '#':breakinputList.append(Input.split())
rome = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}
def romeToInt(s):result = 0limit = len(s)i = 0while i < limit:if(i == limit - 1):result += rome.get(s[i])elif (rome.get(s[i]) >= rome.get(s[i+1])):result += rome.get(s[i])else:result += rome.get(s[i+1]) - rome.get(s[i])i+=2continuei+=1return result
for i in inputList:i[0] = romeToInt(i[0])i[1] = romeToInt(i[1])
def intToRome(s):result = ""if s == 0:return "ZERO"while(True):if s >= 1000:result += "M"s -= 1000elif s >= 900:result += "CM"s -= 900elif s >= 500:result += "D"s -= 500elif s >= 400:result += "CD"s -= 400elif s >= 100:result += "C"s -= 100elif s >= 90:result += "XC"s -= 90elif s >= 50:result += "L"s -= 50elif s >= 40:result += "XL"s -= 40elif s >= 10:result += "X"s -= 10elif s >= 9:result += "IX"s -= 9elif s >= 5:result += "V"s -= 5elif s >= 4:result += "IV"s -= 4elif s >= 1:result += "I"s -= 1else:break
return result
for i in inputList:print(intToRome(i[0]-i[1]))
第二個數字可能比較大,此時你會沒有輸出