반응형
1620번: 나는야 포켓몬 마스터 이다솜
첫째 줄에는 도감에 수록되어 있는 포켓몬의 개수 N이랑 내가 맞춰야 하는 문제의 개수 M이 주어져. N과 M은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수인데, 자연수가 뭔지는 알지? 모르면
www.acmicpc.net
알고리즘 분류
- 자료 구조
- 해시를 사용한 집합과 맵
SOLUTION
import sys
N, M = map(int, sys.stdin.readline().split())
pokemon_dict = {}
for number in range(1,N+1):
pokemon_name = sys.stdin.readline()
pokemon_dict[pokemon_name] = number # key = pokemon_name, value = number
pokemon_key = list(pokemon_dict.keys()) # 번호로 포켓몬을 찾을 때를 위해 pokemon_key 생성
for _ in range(M):
pokemon = sys.stdin.readline()
if pokemon in pokemon_dict.keys(): # 포켓몬 이름으로 들어올 때
print(pokemon_dict[pokemon], end = "\n")
else: # 번호로 들어올 때
print(pokemon_key[int(pokemon)-1], end = "")
'코딩테스트 대비 > BOJ' 카테고리의 다른 글
[Baekjoon/Python] 1764번: 듣보잡 - 효과는 굉장했다! (0) | 2021.11.09 |
---|---|
[Baekjoon/Python] 1676번: 팩토리얼 0의 개수 - 효과는 굉장했다! (0) | 2021.11.09 |
[Baekjoon/Python] 11723번: 집합 - 효과는 굉장했다! (0) | 2021.11.04 |
[Baekjoon/Python] 18111번: 마인크래프트 - 효과는 굉장했다! (0) | 2021.11.02 |
[Baekjoon/Python] 2805번: 나무 자르기 - 효과는 굉장했다! (0) | 2021.11.02 |