Python
시간초과
from itertools import count
import sys
n = sys.stdin.readline().rstrip()
array_n = list(map(int, sys.stdin.readline().rstrip().split()))
m = sys.stdin.readline().rstrip()
array_m = list(map(int, sys.stdin.readline().rstrip().split()))
for i in array_m:
cnt = 0
for j in array_n:
if i == j:
cnt += 1
print(cnt, end=" ")
딕셔너리를 활용
import sys
n = sys.stdin.readline().rstrip()
array_n = list(map(int, sys.stdin.readline().rstrip().split()))
m = sys.stdin.readline().rstrip()
array_m = list(map(int, sys.stdin.readline().rstrip().split()))
dict_n = dict()
for i in array_n:
if i not in dict_n.keys() :
dict_n[i] =1
else:
dict_n[i] = dict_n[i]+1
for i in array_m :
if i in dict_n.keys() :
print(dict_n[i], end= " ")
else :
print(0, end=" ")