python求助,两个过的剩下的有WA也有RE

P1055 [NOIP2008 普及组] ISBN 号码

Wangrh @ 2024-01-20 20:14:20

ibn = list(input().strip())
x = int(ibn[0]) * 1 + int(ibn[2]) * 2 + int(ibn[0]) + int(ibn[3]) * 3 + int(ibn[4]) * 4 + int(ibn[6]) * 5 + int(
    ibn[7]) * 6
x = (x + int(ibn[8]) * 7 + int(ibn[9]) * 8 + int(ibn[10]) * 9) % 11
if x == int(ibn[12]):
    print('Right', end='')
else:
    for i in range(len(ibn) - 1):
        print(ibn[i], end='')
    print(x, end='')

by Winds_Land @ 2024-01-23 17:45:04

# 读入
isbn = list(input())
# '-'的下标位置列表
lst = [1,5,11]
# 校验和初始化
checksum = 0
# 倒着读lst,防止删除元素后导致下标变化
for i in lst[::-1]:
    del isbn[i]
# 计算校验和
for i in range(len(isbn)-1):
    checksum += int(isbn[i]) * (i + 1)
checksum %= 11
last = str(checksum)
# 求余为10则变为'X'
if last == '10':
    last = 'X'
# 校验和检测
if last == isbn[-1]:
    print("Right")
else:
    # 重新加入'-'
    for i in lst:
        isbn.insert(i,'-')
    isbn[-1]=last
    print(''.join(isbn))

刚写的,你看看


|