python-algorithm
백준 10816 숫자 카드 2
무적김두칠
2022. 11. 8. 19:47
https://www.acmicpc.net/problem/10816
10816번: 숫자 카드 2
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import sys
from collections import Counter
n=int(sys.stdin.readline())
cards=list(map(int, sys.stdin.readline().split()))
m=int(sys.stdin.readline())
to_find=list(map(int, sys.stdin.readline().split()))
counter_cards = Counter(cards)
for i in to_find:
#if i!=to_find[-1]:
print(counter_cards[i], end=' ')
# else:
# print(counter_cards[i], end='')
#print(counter_cards)
|
cs |
이분탐색 bisect를 써도 되긴하는데 Counter 쓰는게 좀 더 편한것같더라구용
출력에만 조심하셔요
Using bisect or Counter doesn't matter, but It is easier for me to use Counter
But Watch out your print
반응형