2018 KAKAO BLIND RECRUITMENT
- queue와 list사용
from collections import deque
def solution(msg):
answer = []
dics = []
que=deque(msg)
dics=[chr(i) for i in range(ord('A'),ord('Z')+1)] #A:0,B:1,..
tmp=''
while len(que)>0:
tmp=''
for _ in range(0,len(que)):
tmp+=que[0]
if tmp in dics:
que.popleft()
else: #사전에 포함이 안될 때
answer.append(dics.index(tmp[:-1])+1) #사전에 포함안되는 문자는 빼기
dics.append(tmp)
break
answer.append(dics.index(tmp)+1)
return answer
'IT > coding study' 카테고리의 다른 글
[acmicpc] 3190. 뱀 (python) (0) | 2022.03.07 |
---|---|
[programmers] [3차] n진수 게임 (python) (0) | 2022.01.24 |
[programmers] [3차] 방금그곡 (python) (0) | 2022.01.17 |
[programmers] 크레인 인형뽑기 게임 (python) (0) | 2022.01.10 |
[acmicpc] 8911. 거북이(python) (0) | 2021.12.27 |