https://www.acmicpc.net/problem/1620
1
2
3
4
5
6
7
8
9
10
11
12
13
|
import sys
n , m =map(int,sys.stdin.readline().split())
pokemon = dict()
for i in range(1,n+1):
name = sys.stdin.readline().rstrip()
pokemon[name] = i
pokemon_reversed = dict(map(reversed, pokemon.items()))
for i in range(m):
target=sys.stdin.readline().rstrip()
if target.isnumeric():
print(pokemon_reversed[int(target)])
else:
print(pokemon[target])
|
cs |
딕셔너리 사용하면 되고
Line 7 처럼 index가 입력되는 경우를 위해 키, 벨류를 서로 바꾼 딕셔너리도 추가해줍니다
Using dictionary, In line 7 We need key and value changed dictionary for index of input.
그리고 속도 문제로 인해서 input() 대신 sys.stdin.readline()을 사용하고 '\n' 과 같은 개행문자 를 지우기위해 .rstrip()을 사용합니다.
With time limit , Stead of input(), use sys.stdin.readline()
반응형
'python-algorithm' 카테고리의 다른 글
백준 11576 Base Conversion (0) | 2022.11.10 |
---|---|
백준 18258 큐 2 (0) | 2022.11.09 |
백준 4949 균형잡힌 세상 (0) | 2022.11.09 |
백준 18398 HOMWRK (0) | 2022.11.09 |
백준 1966 프린터 큐 (0) | 2022.11.08 |
댓글