문제
1620번: 나는야 포켓몬 마스터 이다솜
첫째 줄에는 도감에 수록되어 있는 포켓몬의 개수 N이랑 내가 맞춰야 하는 문제의 개수 M이 주어져. N과 M은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수인데, 자연수가 뭔지는 알지? 모르면
www.acmicpc.net
코드
My answer
import sys
input=sys.stdin.readline
dogam_n=dict()
dogam_w=dict()
n,m=map(int,input().split())
for i in range(n):
name=input().rstrip()
dogam_n[i+1]=name
dogam_w[name]=i+1
for i in range(m):
q=input().rstrip()
if(q[0].isalpha()):
print(dogam_w[q])
else:
print(dogam_n[int(q)])
Another answer
import sys
input=lambda:sys.stdin.readline().strip()
dic={}
a,b=map(int,input().split())
for i in range(a):
s=input()
dic[s]=str(i+1)
dic[str(i+1)]=s
for i in range(b):
print(dic[input()])
풀이
바보같았다 굳이 딕셔너리 2개를 왜만들었을까 난 번호:이름 도감이랑 이름:번호 도감을 따로 만들었는데 그냥 하나로 만들었으면 됐다. 바보같네
728x90
'코딩테스트 > 백준[Python]' 카테고리의 다른 글
| [Python] 백준 #10546- 배부른 마라토너 (0) | 2022.01.23 |
|---|---|
| [Python] 백준 #14425- 문자열집합 (0) | 2022.01.22 |
| [Python] 백준 #2346- 풍선 터뜨리기 (0) | 2022.01.21 |
| [Python] 백준 #1935- 후위 표기식2 (0) | 2022.01.21 |
| [Python] 백준 #9184- 신나는 함수 실행 (0) | 2022.01.20 |