身份证验证-乙级题目

n=int(input())
a=[]
while n>0:
    st=input()
    a.append(st)
    n=n-1
b=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2]
M=['1','0','X','9','8','7','6','5','4','3','2']
res=[]
for st in a:
    c=0
    if 'X' in st[:18]:
        res.append(st)
        continue
    for i in range(len(st)-1):
        c=c+int(st[i])*b[i]
    if c%11!=M.index(st[17]):
        res.append(st)
if len(res)==0:
    print("All passed")
else:
    for i in res:
        print(i)

 这个答案没有通过所有的测试点,但是这个题并不算难,乙级题目。

猜你喜欢

转载自www.cnblogs.com/zju21860/p/10052224.html