#36044: 卡line 8,不知道問題出在哪,自己試了幾組testData都沒問題


s10810153@tcsh.hlc.edu.tw (程式垃圾)

學校 : 花蓮縣慈濟大學附中
編號 : 213518
來源 : [140.115.200.135]
最後登入時間 :
2022-10-29 00:27:54
a013. 羅馬數字 -- NPSC 模擬試題 | From: [140.115.200.135] | 發表日期 : 2023-07-01 18:17

inputList = []
while True:
    Input = input()
    if Input == '#':
        break
    inputList.append(Input.split())

rome = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}

def romeToInt(s):
    result = 0
    limit = len(s)
    i = 0
    while 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+=2
            continue
        i+=1
    return 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 -= 1000
        elif s >= 900:
            result += "CM"
            s -= 900
        elif s >= 500:
            result += "D"
            s -= 500
        elif s >= 400:
            result += "CD"
            s -= 400
        elif s >= 100:
            result += "C"
            s -= 100
        elif s >= 90:
            result += "XC"
            s -= 90
        elif s >= 50:
            result += "L"
            s -= 50
        elif s >= 40:
            result += "XL"
            s -= 40
        elif s >= 10:
            result += "X"
            s -= 10
        elif s >= 9:
            result += "IX"
            s -= 9
        elif s >= 5:
            result += "V"
            s -= 5
        elif s >= 4:
            result += "IV"
            s -= 4
        elif s >= 1:
            result += "I"
            s -= 1
        else:
            break

    return result

for i in inputList:
    print(intToRome(i[0]-i[1]))
 
 
 
#36047: Re: 卡line 8,不知道問題出在哪,自己試了幾組testData都沒問題


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [101.136.203.77]
最後登入時間 :
2024-04-07 15:34:14
a013. 羅馬數字 -- NPSC 模擬試題 | From: [39.15.34.79] | 發表日期 : 2023-07-01 22:56

inputList = []
while True:
    Input = input()
    if Input == '#':
        break
    inputList.append(Input.split())

rome = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000}

def romeToInt(s):
    result = 0
    limit = len(s)
    i = 0
    while 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+=2
            continue
        i+=1
    return 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 -= 1000
        elif s >= 900:
            result += "CM"
            s -= 900
        elif s >= 500:
            result += "D"
            s -= 500
        elif s >= 400:
            result += "CD"
            s -= 400
        elif s >= 100:
            result += "C"
            s -= 100
        elif s >= 90:
            result += "XC"
            s -= 90
        elif s >= 50:
            result += "L"
            s -= 50
        elif s >= 40:
            result += "XL"
            s -= 40
        elif s >= 10:
            result += "X"
            s -= 10
        elif s >= 9:
            result += "IX"
            s -= 9
        elif s >= 5:
            result += "V"
            s -= 5
        elif s >= 4:
            result += "IV"
            s -= 4
        elif s >= 1:
            result += "I"
            s -= 1
        else:
            break

    return result

for i in inputList:
    print(intToRome(i[0]-i[1]))
 
 


第二個數字可能比較大,此時你會沒有輸出

 
ZeroJudge Forum