编程语言
首页 > 编程语言> > pat 乙类 1038 python 超时

pat 乙类 1038 python 超时

作者:互联网

使用列表储存数据,需要创建序列号,要不然会超出索引,最后一个测试点超时

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=' ')

标签:pat,python,range,int,1038,score,result,input,seek
来源: https://blog.csdn.net/qq_20662425/article/details/120102127