Study/코딩테스트
[ 프로그래머스 / 2021 KAKAO BLIND RECRUITMENT / Python ] 신규 아이디 추천
까다로운오리
2022. 3. 7. 17:57
문제 설명
https://programmers.co.kr/learn/courses/30/lessons/72410?language=python3
코딩테스트 연습 - 신규 아이디 추천
카카오에 입사한 신입 개발자 네오는 "카카오계정개발팀"에 배치되어, 카카오 서비스에 가입하는 유저들의 아이디를 생성하는 업무를 담당하게 되었습니다. "네오"에게 주어진 첫 업무는 새로
programmers.co.kr
문제 풀이
from collections import deque
def first_second(new_id_lst):
temp = []
symbol = ['.','_','-']
i = 0
while new_id_lst:
word = new_id_lst.popleft()
if word.isalpha():
temp.append(word.lower())
elif 48 <= ord(word) and ord(word) <= 57:
temp.append(word)
elif word in symbol:
temp.append(word)
i += 1
return deque(temp)
def third_forth(new_id_lst):
pre, i = 0, 0
temp = []
while new_id_lst:
word = new_id_lst.popleft()
if i == 0 and word =='.':
continue
if pre == word and word == '.':
pre = word
continue
else:
temp.append(word)
i += 1
pre = word
if temp:
if temp[-1] == '.':
temp.pop()
return temp
def fifth_sixth_seventh(new_id_lst):
if len(new_id_lst) >= 16:
new_id_lst = new_id_lst[:15]
state = True
while state:
if new_id_lst[-1] == '.':
new_id_lst.pop()
else:
state = False
elif len(new_id_lst) == 0:
new_id_lst.append('aaa')
elif len(new_id_lst) <= 2:
while len(new_id_lst) <3:
new_id_lst.append(new_id_lst[-1])
return "".join(new_id_lst)
def solution(new_id):
answer = ''
new_id_lst = deque(new_id)
new_id_lst = first_second(new_id_lst)
if new_id_lst:
new_id_lst = third_forth(new_id_lst)
return fifth_sixth_seventh(new_id_lst)