#25657: 求救!請問錯在哪?


135792468ay@gmail.com (陳蓉瑄)

學校 : 不指定學校
編號 : 153411
來源 : [124.219.6.236]
最後登入時間 :
2022-01-14 15:27:40
a013. 羅馬數字 -- NPSC 模擬試題 | From: [112.104.64.41] | 發表日期 : 2021-06-10 12:23

一直顯示:
您的程式被監控系統中斷,可能是程式無法正常結束所導致。
Traceback (most recent call last):
  File "/7683207/code_7683207.py", line 16, in 
    for y in x[a] :
IndexError: list index out of range

但我用https://replit.com嘗試並沒有這個問題

 
while True:
 
try:
 
m=input()

except:
break
 
X=[]
for a in range(2):

Z=[]
x=m.split()
for y in x[a] :
if y =='I':
Z.append(1)
if y=='V':
Z.append(5)
if y=='X':
Z.append(10)
if y=='L':
Z.append(50)
if y=='C':
Z.append(100)
if y=='D':
Z.append(500)
if y=='M':
Z.append(1000)
t=0
Y=[]
 
if len(Z) ==1:
Y.append(Z[0])
else:
while t+1 < len(Z) :
if Z[t+1]>Z[t]:
Y.append(Z[t+1]-Z[t])
t=t+2
else:
Y.append(Z[t])
t=t+1
if t+1 == len(Z) :
Y.append(Z[t])
 
X.append(sum(Y))
 
 
 
if X[0]==X[1]:
print('ZERO')
else:
if X[0]>X[1]:
number=X[0]-X[1]
if X[0]<X[1]:
number=X[1]-X[0]
 
 
while number>=1000:
print('M',end='')
number=number-1000
while number>=900:
print('CM',end='')
number=number-900
while number>=500:
print('D',end='')
number=number-500
while number>=400:
print('CD',end='')
number=number-400
while number>=100:
print('C',end='')
number=number-100
while number>=90:
print('XC',end='')
number=number-90
while number>=50:
print('L',end='')
number=number-50
while number>=40:
print('XL',end='')
number=number-40
while number>=10:
print('X',end='')
number=number-10
while number>=9:
print('IX',end='')
number=number-9
while number>=5:
print('V',end='')
number=number-5
while number>=4:
print('IV',end='')
number=number-4
while number>=1:
print('I',end='')
number=number-1

print(end='\n')
#print(m)
continue

 



 
ZeroJudge Forum