BOJ10816 숫자 카드 2
실버IV | 백준 10816 | Python3 파이썬 풀이
Python Collections의 Counter를 이용한다.
cardcounter = Counter(cards)
Counter를 이용해 카드의 각 숫자의 개수를 센다.
print(*(f'{cardcounter[m]}' if m in cardcounter else '0' for m in deck))
덱에 있는 카드 순서대로 Counter에 존재하면 개수를, 없다면 0을 출력한다.
import sys
from collections import Counter
input = sys.stdin.readline
input() # N
cards = input().rstrip().split()
input() # M
deck = input().rstrip().split()
# Counter
cardcounter = Counter(cards)
print(*(f'{cardcounter[m]}' if m in cardcounter else '0' for m in deck))