본문 바로가기
python-algorithm

백준 10816 숫자 카드 2

by 무적김두칠 2022. 11. 8.

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

반응형

'python-algorithm' 카테고리의 다른 글

백준 18398 HOMWRK  (0) 2022.11.09
백준 1966 프린터 큐  (0) 2022.11.08
백준 11866 요세푸스 문제 0  (0) 2022.11.08
Hacker rank Super Reduced String  (0) 2022.11.08
백준 18511 큰 수 구성하기  (0) 2022.11.08

댓글