[백준 문제풀이] 1620 - 나는야 포켓몬 마스터 이다솜
풀이
파이썬에서 ‘도감’이란 말을 들으면 ‘딕셔너리’를 사용하면 가볍게 해결할 수 있는 느낌이 든다. 딕셔너리를 사용해 번호와 이름을 부여하고 .isdigit()
함수를 이용해 숫자인지 문자인지 판별해 해결하면 되는 쉬운 문제이다.
코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import sys
print = sys.stdout.write
input = sys.stdin.readline
N, M = map(int, input().split())
pokeDic = {}
for i in range(1, N + 1):
name = str(input()).rstrip()
pokeDic[i] = name
pokeDic[name] = i
temp = [0] * M
for i in range(M):
temp[i] = input().rstrip()
for i in range(M):
if temp[i].isdigit():
print("".join(pokeDic[int(temp[i])] + "\n"))
else:
print("".join(str(pokeDic[temp[i]]) + "\n"))
댓글남기기