Published:
Updated:

  • Reference
  • 이해는 잘 안 됐지만 문제가 귀여워서 풀어봤다 ㅋㅋㅋㅋ
  • solution()에서 input을 같이 해주는 게 조금 마음에 안 들긴 한다


Solution

import collections
import sys
from typing import List


def solution(n: int, m: int) -> List[str]:
    answer = []

    index_name_map = collections.defaultdict(int)
    name_index_map = collections.defaultdict(str)

    for i in range(1, n + 1):
        name = sys.stdin.readline().rstrip()
        name_index_map[name] = i
        index_name_map[i] = name

    for j in range(m):
        name = sys.stdin.readline().rstrip()

        if name.isdigit():
            answer.append(index_name_map[int(name)])
            continue

        answer.append(name_index_map[name])

    return answer


N, M = map(int, sys.stdin.readline().split())
print(*solution(N, M), sep='\n')

Leave a comment