PS/Python
[Python] 백준(BOJ) 10816번: 숫자 카드2
yoo.o
2020. 10. 15. 02:47
반응형
문제
10816번: 숫자 카드 2
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
풀이
숫자카드에서는 들어있는지 여부만 출력하면 됐지만 숫자카드2에서는 몇개가 있는지 출력해야한다.
collections의 Counter를 사용해서 딕셔너리 형태로 횟수를 받고, 출력했다
import sys
from collections import Counter
N = sys.stdin.readline()
A = Counter(sys.stdin.readline().strip().split(" "))
M = sys.stdin.readline()
B = sys.stdin.readline().strip().split(" ")
for each in B:
print(A[each], end=" ")
반응형