[ALGORITHM] BOJ 10816. 숫자 카드 2
less than 1 minute read
ALGORITHM Übung - 백준
문제
코드
import sys
from collections import Counter
def num_of_cards(cards,interest):
c = Counter(cards)
return [c[i] for i in interest] # if not in interest 0
if __name__ == "__main__":
n = int(input())
cards = list(map(int,sys.stdin.readline().split()))
m = int(input())
interest = list(map(int,sys.stdin.readline().split()))
print(' '.join(str(x) for x in num_of_cards(cards, interest)))
# 다른 풀이 방법
import sys
from bisect import bisect_left, bisect_right
def num_of_cards(cards, interest):
return bisect_right(cards, interest) - bisect_left(cards, interest)
if __name__ == "__main__":
n = int(input())
cards = sorted(list(map(int, sys.stdin.readline().split())))
m = int(input())
interests = list(map(int, sys.stdin.readline().split()))
for interest in interests:
print(num_of_cards(cards, interest), end=" ")