문제
코딩테스트 연습 - 신규 아이디 추천
카카오에 입사한 신입 개발자 네오는 "카카오계정개발팀"에 배치되어, 카카오 서비스에 가입하는 유저들의 아이디를 생성하는 업무를 담당하게 되었습니다. "네오"에게 주어진 첫 업무는 새로
programmers.co.kr
알고리즘
- 단계별로 알고리즘을 작성하면 된다.
- 다른 사람들의 풀이를 보니 정규표현식에 대해 공부를 해야 할 것 같다.
코드
# 21:20
def solution(new_id):
answer = ''
l = len(new_id)
# 반복문을 통해 id를 확인
for i in range(l):
# 1단계
if new_id[i].isupper():
answer += new_id[i].lower()
# 3단계
elif len(answer) > 0 and answer[-1] == "." and new_id[i] == ".":
continue
# 2단계
elif new_id[i] == "-" or new_id[i] == "_" or new_id[i].isdigit() or new_id[i] == "." or new_id[i].islower():
answer += new_id[i]
# 4단계
if len(answer) > 0 and answer[0] == ".":
answer = ""
# 6단계
answer = answer[0:15]
if len(answer) > 0:
# 4단계
if answer[-1] == ".":
answer = answer[:len(answer) - 1]
# 7단계
while len(answer) < 3:
answer += answer[-1]
else:
# 5단계
answer = "aaa"
return answer
github
GitHub - junjange/CodingTest: 내가 푼 코딩 테스트 문제와 해결법
내가 푼 코딩 테스트 문제와 해결법. Contribute to junjange/CodingTest development by creating an account on GitHub.
github.com
'CodingTest > Programers' 카테고리의 다른 글
[programers] 프로그래머스(파이썬) : 영어 끝말잇기 (0) | 2022.04.24 |
---|---|
[programers] 프로그래머스(파이썬) : 배달 (0) | 2022.04.24 |
[programers] 프로그래머스(파이썬) : 로또의 최고 순위와 최저 순위 (0) | 2022.04.24 |
[programers] 프로그래머스(파이썬) : 소수 만들기 (0) | 2022.04.24 |
[programers] 프로그래머스(파이썬) : 신고 결과 받기 (0) | 2022.04.23 |