BAEKJOON/binary search

[baekJoon10816] 숫자 카드 2(Counter 정리)

ferozsun 2023. 10. 25. 16:24

 

https://www.acmicpc.net/problem/10816

 

10816번: 숫자 카드 2

첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,0

www.acmicpc.net


* Counter: 리스트 각 요소의 개수 구할때 사용

from collections import Counter

l = [1, 2, 3, 3, 4, 5, 6, 6, 6]

c = Counter(l)

print(c[2]) # 1
print(c[6]) # 3
print(c[9]) # 0

import sys
from collections import Counter
# sys.stdin.readline()

sys.stdin.readline()
n = sys.stdin.readline().split()
sys.stdin.readline()
f = sys.stdin.readline().split()

c = Counter(n)

ret = ''

for i in f:
    print(c[i], end=' ')