BOJ10816 숫자 카드 2

Hoeun Lee·2021년 8월 21일
0

백준 알고리즘 풀이

목록 보기
12/34
post-thumbnail

문제

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

결과

profile
건국대학교 컴퓨터공학부 이호은 | 알고리즘 정리 블로그

0개의 댓글