ACXX @ 2022-08-04 11:03:11
isbn = input('') + '-'
getl = []
for i in isbn:
if i == '-':
pass
else:
getl.append(i)
last = getl.pop(-1)
if last == 'X':
pass
else:
last = int(last)
check = 0
flag = 0
for i in range(len(getl)):
check += int(getl[i]) * (i + 1)
if check % 11 == 10:
flag = 'X'
else:
flag = check % 11
if flag == last:
print('Right')
else:
print('{}-{}-{}-{}'.format(getl[0], ''.join(getl[1:4]), ''.join(getl[4:]), flag))
by nine_xxaof_IIIo @ 2022-08-04 11:50:11
你加个注释吧,在下懒得看代码
by ACXX @ 2022-08-05 09:04:29
@wangjiaxiQWQ 那我问你干嘛qwq
by Gorun @ 2022-08-06 18:47:29
我也是出了点问题,老是RE不过。
后来发现列表的下标用-1会导致玄学错误。可能是洛谷对python的支持不友好。
你要不试试别用-1?看到你有写pop,但应该是一样的
by ACXX @ 2022-08-09 11:39:57
@Gorun 换成了len()-1, 还是RE,哎
by Gorun @ 2022-08-12 11:39:22
@ACXX 试一下使用input().strip()
代替单纯的input()
,其他帖子中有人提到这一点
我猜测可能是那个数据点有多余的玄学空字符导致的
by ACXX @ 2022-08-12 17:24:48
@Gorun xiexie
by demons1014 @ 2022-09-17 18:07:10
isbn = list(input())
for i in isbn:
if i == '-':
isbn.remove(i)
num = 0
s = 0
for i in range(len(isbn[:9])):
# print(f"s + {isbn[i]}*{i+1} = {(int(isbn[i])*(i+1))+s}")
s += int(isbn[i])*(i+1)
num = s%11
if num == 10:
num = 'X'
#print(len(isbn))
if isbn[9] == str(num):
print('Right')
else:
print(f'{isbn[0]}-{isbn[1]}{isbn[2]}{isbn[3]}-{isbn[4]}{isbn[5]}{isbn[6]}{isbn[7]}{isbn[8]}-{num}')