알고리즘
[백준 10816] 숫자 카드 2 - 자료구조, 정렬(?), 이분탐색(?)
kyeongjun-dev
2022. 1. 14. 14:48
코드
from collections import Counter
def solution(arr):
# Counter dict : Counter({10: 3, 3: 2, -10: 2, 6: 1, 2: 1, 7: 1})
cd = Counter(arr)
input()
# input : 10 9 -5 2 3 4 5 -10
keys = list(map(int, input().split()))
# output : 3 0 0 1 2 0 0 2
for key in keys:
print(cd[key], end=' ')
input()
# input : 6 3 2 10 10 10 -10 -10 7 3
arr = list(map(int, input().split()))
solution(arr)
Counter는 배열에서 각 원소가 몇번 쓰였는지 count 하여 원소를 key로 하는 dict 형태로 반환함