https://www.acmicpc.net/problem/10816
10816๋ฒ: ์ซ์ ์นด๋ 2
์ฒซ์งธ ์ค์ ์๊ทผ์ด๊ฐ ๊ฐ์ง๊ณ ์๋ ์ซ์ ์นด๋์ ๊ฐ์ N(1 โค N โค 500,000)์ด ์ฃผ์ด์ง๋ค. ๋์งธ ์ค์๋ ์ซ์ ์นด๋์ ์ ํ์๋ ์ ์๊ฐ ์ฃผ์ด์ง๋ค. ์ซ์ ์นด๋์ ์ ํ์๋ ์๋ -10,000,000๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ๊ณ , 10,
www.acmicpc.net
์ฑ์ ํ๋๋ฐ๋ง 1๋ถ 30์ด๋ ๊ฑธ๋ ค์ ๋ ์ฒ์์ ์๊ฐ ์ด๊ณผ ๋จ๋ ์ค^^,,
import sys
n = int(input())
card = sorted(map(int, sys.stdin.readline().split()))
m = int(input())
find = list(map(int, sys.stdin.readline().split()))
dict_card = dict()
for i in card:
if i in dict_card:
dict_card[i] += 1
else:
dict_card[i] = 1
for i in find:
if i in dict_card:
print(dict_card[i], end=' ')
else:
print(0, end=' ')
์๋ ์ด์งํ์ -> ์ฐพ์ผ๋ฉด ์๋ค ์ธ๋ฑ์ค ํ์ธํด๊ฐ๋ฉด์ ๊ฐ์ ์์๋ฅผ ์ฐพ์
์ด๋ ๊ฒ ํ๋ ค๊ณ ํ๋๋ฐ ๋ณต์กํ๊ณ ๋นํจ์จ์ ์.. ๋ด๊ฐ ์๊ฐํด๋ ์ด๊ฑด ์๋๋ค ์ถ์๋ค
๋์ ๋๋ฆฌ๋ฅผ ์ด์ฉํด์ {๊ฐ:๊ฐ์} ํํ๋ก ์ ์ฅํ๊ณ ๊ฐ์ ์ฐพ์ผ๋ฉด ๊ฐ์๋ฅผ ์ถ๋ ฅํ๊ฒ ํ๋ค
์ด์งํ์์ ์ด์ฉํ์ง ์์๋ ํ๋ฆฌ๋ ๋ฌธ์ ๋ค!
'๐ค > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋ฐฑ์ค 2805: ๋๋ฌด ์๋ฅด๊ธฐ (Python) (0) | 2022.02.12 |
---|---|
๋ฐฑ์ค 1654: ๋์ ์๋ฅด๊ธฐ (Python) (0) | 2022.02.11 |
๋ฐฑ์ค 1920: ์ ์ฐพ๊ธฐ (Python) (0) | 2022.02.10 |
๋ฐฑ์ค 1707: ์ด๋ถ๊ทธ๋ํ (Python) (0) | 2022.02.03 |
๋ฐฑ์ค 7564: ๋์ดํธ์ ์ด๋ (Python) (0) | 2022.02.03 |