ETC/Algorithm
백준, 숫자 카드2, 10816
coding_genie
2024. 9. 4. 01:28
[유형]
이분탐색
[문제링크]
https://www.acmicpc.net/problem/10816
[요약]
숫자 카드는 정수 하나가 적혀져 있는 카드이다. 상근이는 숫자 카드 N개를 가지고 있다. 정수 M개가 주어졌을 때, 이 수가 적혀있는 숫자 카드를 상근이가 몇 개 가지고 있는지 구하는 프로그램을 작성하시오.
[문제풀이]
collections의 Counter를 사용한다.
import sys
from collections import Counter
def input():
return sys.stdin.readline().rstrip()
list_n = []
list_m = []
n = int(input())
list_n = list(map(int, input().split()))
m = int(input())
list_m = list(map(int, input().split()))
count = Counter(list_n)
for m in list_m:
if m in count:
print(count[m], end=' ')
else:
print(0, end=' ')