1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: a2htray
# create date: 2023/3/12
"""
PAT 乙级 1031
"""
weights = [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']
def weight_sum(digits):
total = 0
for i, digit in enumerate(digits):
total += digit * weights[i]
return total
if __name__ == '__main__':
n = int(input())
not_passed = []
for _ in range(n):
line = input()
if len(line) != 18:
not_passed.append(line)
continue
all_digit = True
for c in line[:17]:
if not c.isdigit():
all_digit = False
if not all_digit:
not_passed.append(line)
continue
ws = weight_sum(list(map(int, line[:17])))
z = ws % 11
if m[z] != line[17]:
not_passed.append(line)
if len(not_passed) == 0:
print('All passed')
else:
for item in not_passed:
print(item)
|