๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
  • What would life be If we had no courage to attemp anything?
Problem Solving/BAEKJOON

[baekjoon]python #10816 ์ˆซ์ž ์นด๋“œ 2

by DevIseo 2022. 6. 3.

https://www.acmicpc.net/problem/10816

 

10816๋ฒˆ: ์ˆซ์ž ์นด๋“œ 2

์ฒซ์งธ ์ค„์— ์ƒ๊ทผ์ด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ˆซ์ž ์นด๋“œ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 500,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ˆ˜๋Š” -10,000,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 10,

www.acmicpc.net

์ฒ˜์Œ์—๋Š” ์ด๋ถ„ํƒ์ƒ‰์„ ์ด์šฉํ•ด ํ’€์–ด๋ณด๋ ค๊ณ  ํ–ˆ์ง€๋งŒ, ์ž˜ ๋˜์ง€ ์•Š์•„์„œ ๊ตฌ๊ธ€ ๊ฒ€์ƒ‰์„ ํ†ตํ•ด ํ•ด์‰ฌ๋ฅผ ์ด์šฉํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ํ’€์ด ํ•  ์ˆ˜ ์žˆ์Œ์„ ์•Œ๊ฒŒ๋˜์—ˆ๋‹ค.

๋จผ์ € ๋”•์…”๋„ˆ๋ฆฌ ํ˜•ํƒœ๋กœ hash๋ผ๋Š” ๋”•์…”๋„ˆ๋ฆฌ์— ๊ฐ’์„ ๋„ฃ์–ด์ค€ ํ›„ ๋‹ค์‹œ ํ˜ธ์ถœํ•ด ์ถœ๋ ฅํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))
m = int(input())
B = list(map(int,input().split()))


hash = {}
for a in A:
    if a in hash:
        hash[a]+=1
    else:
        hash[a]=1
# print(hash)
for b in B:
    if b in hash:
        print(hash[b],end=' ')
    else:
        print(0,end=' ')

๋Œ“๊ธ€