使用列表储存数据,需要创建序列号,要不然会超出索引,最后一个测试点超时
n = int(input())
score = list(map(int,input().split()))
m = list(map(int,input().split()))
k = m[0]
seek = m[1:]
result = []
for i in range(k):
result.append(0)
for j in range(n):
if seek[i] == score[j]:
result[i] += 1
for i in range(k):
if i == k-1:
print(result[i],end='')
else:
print(result[i],end=' ')
不使用列表,直接输出,也超时了
n = int(input())
score = list(map(int,input().split()))
m = list(map(int,input().split()))
k = m[0]
seek = m[1:]
for i in range(k):
count = 0
for j in range(n):
if seek[i] == score[j]:
count += 1
if i == k-1:
print(count,end='')
else:
print(count,end=' ')