ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

728x90
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

 

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

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

www.acmicpc.net

 

๋ฌธ์ œ ํ’€์ด

์•ž์„œ ๋‹ค๋ฃฌ ์ˆซ์ž ์นด๋“œ ๋ฌธ์ œ์™€ ๋‹ฌ๋ฆฌ, M๊ฐœ์˜ ์นด๋“œ ์ค‘์— N๊ฐœ์˜ ์นด๋“œ์— ํฌํ•จ ๋˜๋Š” ๊ฒฝ์šฐ ์นด๋“œ์˜ ๊ฐœ์ˆ˜๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค. ๋”ฐ๋ผ์„œ N๊ฐœ์˜ ์นด๋“œ์˜ ์ค‘๋ณต์„ `set`์œผ๋กœ ์ค‘๋ณต ์—ฌ๋ถ€๋ฅผ ์—†์• ๋Š” ๊ฒƒ์ด ์•„๋‹Œ, `Counter`๋ฅผ ํ†ตํ•ด ๊ฐ ์นด๋“œ๊ฐ€ ๋ช‡ ๊ฐœ์”ฉ ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธํ•˜๋ฉด ๋œ๋‹ค.

 

์ฝ”๋“œ

from sys import stdin
from collections import Counter


if __name__ == "__main__":
    n = int(stdin.readline())
    n_card = Counter(list(map(int, stdin.readline().split())))
    m = int(stdin.readline())
    m_card = list(map(int, stdin.readline().split()))

    for card in m_card:
        if card in n_card:
            print(n_card[card], end=' ')
        else:
            print(0, end=' ')
728x90
๋ฐ˜์‘ํ˜•
๋Œ“๊ธ€
๊ธ€ ๋ณด๊ด€ํ•จ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€