30pts,Python求调

P1055 [NOIP2008 普及组] ISBN 号码

yuechenxi130407 @ 2024-10-04 09:23:47

a=str(input())
cs=1
ans=0
f=0
for i in range(len(a)-1):
    if a[i]>='0' and a[i]<='9':
        ans+=int(a[i])*cs
        cs+=1
if (ans%11==int(a[len(a)-1])) or (ans%11==10 and a[len(a)-1]=='X'):
    print("Right")
    f=1
if f!=1:
    for i in range(len(a)-1):
        print(a[i],end='')
    print(ans%11)

1,3,8AC,

2,4,7,10RE,

5,6,9RE


by CQ_lattle_Z @ 2024-10-04 09:26:36

@yuechenxi130407 《a[i]<='9'》 字符串怎么能比呢?


by mazichen @ 2024-10-04 10:03:06

@CQ_lattle_Z 其实是可以的() python会把字符转成ASCII码然后比大小


by CQ_lattle_Z @ 2024-10-04 10:07:30

@mazichen 6我只知道C++会直接报错


by CQ_lattle_Z @ 2024-10-04 10:07:57

等会


by CQ_lattle_Z @ 2024-10-04 10:08:31

@mazichen 哪一题啊


by mazichen @ 2024-10-04 10:11:57

@yuechenxi130407

下载输入输出数据可知

有些输入中给的识别码就是“X”

很明显您的程序并没有考虑这一点


by yuechenxi130407 @ 2024-10-04 11:00:00

@mazichen
谢谢,A了,已关


|