#34809: 程式碼好長... 有人能幫幫修正讓程式碼變得更好嗎?


1365536-1@g.puiching.edu.mo (kingston1234)

學校 : 不指定學校
編號 : 210222
來源 : [60.246.228.36]
最後登入時間 :
2024-10-26 20:50:12
d103. NOIP 2008 1.ISBN号码 -- NOIP2008普及组复赛 | From: [202.86.128.218] | 發表日期 : 2023-04-18 13:48

s=input()
input_code=list(s.replace('-',''))
code = input_code[-1]
if code == 'X':
    code = 10
others = input_code[0:-1]
k=1
sum_final=0
first=""
second=""
third=""
last=""
final_list=[]
ans=""
for i in others:
    sum_final += int(i)*k
    k+=1
correct_ISBN = sum_final%11
if correct_ISBN == int(code):
    print('Right')
elif correct_ISBN == 10 and correct_ISBN != code:
    del input_code[-1]
    input_code.append('X')
    first = str(input_code[0])
    second = str(input_code[1])+str(input_code[2])+str(input_code[3])
    third = str(input_code[4])+str(input_code[5])+str(input_code[6])+str(input_code[7])+str(input_code[8])
    last = str(input_code[-1])
    final_list.append(first)
    final_list.append(second)
    final_list.append(third)
    final_list.append(last)
    ans = "-".join(str(e) for e in final_list)
    print(ans)
else:
    del input_code[-1]
    input_code.append(str(correct_ISBN))
    first = str(input_code[0])
    second = str(input_code[1])+str(input_code[2])+str(input_code[3])
    third = str(input_code[4])+str(input_code[5])+str(input_code[6])+str(input_code[7])+str(input_code[8])
    last = str(input_code[-1])
    final_list.append(first)
    final_list.append(second)
    final_list.append(third)
    final_list.append(last)
    ans = "-".join(str(e) for e in final_list)
    print(ans)

幫幫把程式變得更好吧!

 
ZeroJudge Forum