PAT statistics students with the same score

This question requires reading the results of N students and outputting the number of students who have obtained a given score.

Input format:

Input is given not more than 10 in the first line . 5  is a positive integer N, i.e., the total number of students. The following line gives the percentage scores of N students in percent, separated by spaces. The last line gives the number of scores to be queried K (a positive integer not exceeding N), followed by K scores, separated by spaces.

Output format:

The number of students whose score is equal to the specified score is given in the query order in a row, separated by spaces, but there must be no extra spaces at the end of the row.

Sample input:

10
60 75 90 55 75 99 82 90 75 50
3 75 90 88

Sample output:

3 2 0
t=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
d=[]
for i in range(1,b[0]+1):
    d.append(str(a.count(b[i])))
print(' '.join(d))

It is also very concise code, so fragrant, but unfortunately the last test point has timed out, and I have to talk about the problem of Niuke. The data is really too inconsistent with the meaning of the question. This question actually requires a line of input, not three. OK, tried one line of input, the following code passed

a =  list(map(int, input().split()))
d = []
for i in a[a[0]+2:]:
    d.append(str(a[1:a[0]+1].count(i)))
print(' '.join(d))

Guess you like

Origin www.cnblogs.com/andrew3/p/12710002.html