본문 바로가기

알고리즘/백준 ~ 단계별 풀어보기

백준 1620 "나는야 포켓몬 마스터 이다솜"

Python

import sys


n, k = map(int, sys.stdin.readline().rstrip().split())

pocketMon_Dict_str = dict()
pocketMon_Dict_int = dict()
answer = []

for i in range(1, n+1):
    inp = sys.stdin.readline().rstrip()
    pocketMon_Dict_int[i] = inp
    pocketMon_Dict_str[inp] = i

for j in range(1, k+1):
    inp = sys.stdin.readline().rstrip()
    
    if inp.isnumeric():
        answer.append(pocketMon_Dict_int[int(inp)])
    else :
        answer.append(pocketMon_Dict_str[inp])

for i in answer:
    print(i)