求助各位大佬!为什么会RE(python实现)

P1055 [NOIP2008 普及组] ISBN 号码

Rammer @ 2022-04-19 17:55:35

只有20分,其他点全部是re

x = input()
end = 0
flag = 1
for i in range(len(x)-2):
    if x[i].isdecimal():
        end += flag * int(x[i])
        flag += 1
    continue
code = end % 11
if code==int(x[-1]):
    print("Right")
elif code==10:
    print(x[:-1] + X)
else:
    print(x[:-1] + str(code))

by Rammer @ 2022-04-19 23:46:54

优化了一下代码,减少了输出端口

将切片[:-1]的使用改成了[:12](因为已知输入字符串的长度固定为13)

目前是60 还有4个RE

x = input()
end = 0
flag = 1
for i in range(len(x)-2):
    if x[i].isdecimal():
        end += flag * int(x[i])
        flag += 1
    continue
code = end % 11
if code == 10:
    code = "X"
if code==int(x[12]):
    print("Right")
else:
    print(x[:12] + str(code))

|