PAT 1058 B-choice

The code was released, we learn together, help each other
Title:
Here Insert Picture Description
Input Sample:

3 4 
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (2 b d) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (2 b c) (4 a b c d)

Sample output:

3
6
5
2 2 3 4

Code below (Python):

s, n = [int(x) for x in input().split()]
ques = []
wrong = [0 for x in range(n)]
score = [0 for x in range(s)]
flag = True
for i in range(n):
    ques.append(input())
for i in range(s):
    ans = input().split(') (')
    ans[0] = ans[0].replace('(', '')
    ans[-1] = ans[-1].replace(')', '')
    for j in range(n):
        if ans[j] in ques[j]:
            score[i] += int(ques[j][0])
        else:
            wrong[j] += 1
            flag = False
for i in score:
    print(i)
max_w = max(wrong)
index = []
for i in range(n):
    if wrong[i] == max_w:
        index.append(str(i + 1))
if flag:
    print('Too simple')
else:
    print(max(wrong), end=' ')
    print(' '.join(index))
Published 65 original articles · won praise 25 · views 1040

Guess you like

Origin blog.csdn.net/chongchujianghu3/article/details/104984137