n = int(input())
l = list(map(int, input().split()))
m = int(input())
k = list(map(int, input().split()))
r = []
for i in k:
r.append(l.count(i))
for j in r:
print(j, end= " ")
시간 초과 났다
실버4 문제치고 너무 쉽다는 생각이 들긴했다
n = int(input())
l = list(map(int, input().split()))
m = int(input())
k = list(map(int, input().split()))
n_count = {}
for i in l:
try:
n_count[i] += 1
except:
n_count[i] = 1
res = []
for j in k:
try:
res.append(n_count[j])
except:
res.append(0)
for i in res:
print(i, end=" ")
dict의 key, value 를 활용한 방법이다.
key에 l을 차례대로
value에 각각 I 원소의 갯수
'알고리즘' 카테고리의 다른 글
<백준> 10866번 파이썬 알고리즘 (0) | 2021.07.11 |
---|---|
<백준> 10828번 파이썬 알고리즘 (0) | 2021.07.11 |
<백준> 10814번 파이썬 알고리즘 (0) | 2021.07.10 |
<백준> 10773번 파이썬 알고리즘 (0) | 2021.07.10 |
<백준> 10250번 파이썬 알고리즘 (0) | 2021.07.10 |