728x90
반응형
기본적인 해시 문제이다. dict가 확실히 속도가 빠른 것 같다. 그냥 리스트로 풀면 통과가 안된다.
import sys
N, M = map(int, sys.stdin.readline().rstrip().split())
d1, d2 = {}, {}
for i in range(1, N+1):
s = sys.stdin.readline().rstrip()
d1[s] = i
d2[i] = s
for _ in range(M):
s = sys.stdin.readline().rstrip()
if s.isdigit():
print(d2[int(s)])
else:
print(d1[s])
728x90
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 5525번 IOIOI(python) (0) | 2021.03.18 |
---|---|
백준 알고리즘 2579번 계단 오르기(python) (0) | 2021.03.18 |
백준 알고리즘 11652번 카드(python) (0) | 2021.03.18 |
백준 알고리즘 9184번 신나는 함수 실행(python) (0) | 2021.03.17 |
백준 알고리즘 9461번 파도반 수열(python) (0) | 2021.03.17 |