반응형
Notice
Recent Posts
Recent Comments
Link
동캄의 코딩도장
백준 10816 [숫자 카드 2] 파이썬 본문
반응형
https://www.acmicpc.net/problem/10816
10816번: 숫자 카드 2
첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10,
www.acmicpc.net
# 백준 10816
import sys
input = sys.stdin.readline
N = int(input())
lst = list(map(int, input().split()))
field = [0]*(20000001)
for value in lst:
field[value+10000000] += 1
M = int(input())
search = list(map(int, input().split()))
for value in search:
print(field[value+10000000], end=' ')
단순한 배열을 이용하여 문제를 해결하였다.
from sys import stdin
_ = stdin.readline()
N = map(int,stdin.readline().split())
_ = stdin.readline()
M = map(int,stdin.readline().split())
hashmap = {}
for n in N:
if n in hashmap:
hashmap[n] += 1
else:
hashmap[n] = 1
print(' '.join(str(hashmap[m]) if m in hashmap else '0' for m in M))
딕셔너리를 이용하여 문제를 푸는 방법도 존재한다.
반응형
'코테 > BOJ' 카테고리의 다른 글
백준 1966 [프린터] 파이썬 (0) | 2022.03.07 |
---|---|
백준 1874 [스택 수열] 파이썬 (0) | 2022.03.07 |
백준 4949 [균형잡힌 세상] 파이썬 (0) | 2022.02.12 |
백준 2164 [카드 2] 파이썬 (0) | 2022.02.12 |
백준 1920 [수 찾기] 파이썬 (0) | 2022.02.12 |