Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 힙
- level2
- dfs
- python
- 프로그래머스
- 파이썬
- 코딩테스트
- N과M
- 가상메모리 관리
- 백준
- 다익스트라
- 재귀
- DP
- level0
- 다이나믹 프로그래밍
- MYSQL
- programmers
- dict
- BFS
- level1
- 스택
- 그리디
- 운영체제
- 구현
- 브루트포스
- 가상메모리
- 수학
- level3
- BOJ
- 딕셔너리
Archives
- Today
- Total
동캄의 코딩도장
백준 10816 [숫자 카드 2] 파이썬 본문
https://www.acmicpc.net/problem/10816
# 백준 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 |