[백준] 10816번 : 숫자카드2

letsbebrave·2022년 3월 16일
0

codingtest

목록 보기
44/146

문제

개념

try - except

https://dojang.io/mod/page/view.php?id=2398

딕셔너리를 통한 중복요소 카운팅하기

https://infinitt.tistory.com/78

출력문 print(sep = "", end = "")

https://gilu-world.tistory.com/40

print("1-1칸","1-2칸","1-3칸",end = "")
print("2-1칸","2-2칸","2-3칸",sep = "")

풀이

from sys import stdin

n = int(stdin.readline())
data = list(map(int, stdin.readline().split()))

m = int(stdin.readline())
target = list(map(int, stdin.readline().split()))

count = dict()
for i in data:
    try: count[i] += 1
    except: count[i] = 1
    
for i in target:
    try: print(str(count[i]), end = " ") # 한 줄에 출력 가능
    except: print("0", end = " ")
profile
그게, 할 수 있다고 믿어야 해

0개의 댓글