Link : programmers.co.kr/learn/courses/30/lessons/72410
Python
더보기
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | def solution(new_id): ## 1단계 new_id = new_id.lower() ## 2단계 new_id_str = '' for i in new_id: t_data = ord(i) if (48 <= t_data <= 57) or (t_data == 45) or (t_data == 95) or (t_data == 46) or (97 <= t_data <= 122): new_id_str += i ## 3단계 special_word_continu = [] first = [None, None] for i in range(len(new_id_str)): if new_id_str[i] == '.' and first[0] is None: first[0] = i elif new_id_str[i] == '.' and first[0] is not None: first[1] = i elif new_id_str[i] != '.' and first[0] is not None: if first[1] is not None: special_word_continu.append(first) first = [None, None] if first[1] is not None: special_word_continu.append(first) for i in range(len(special_word_continu) - 1, -1, -1): new_id_str = new_id_str[0:special_word_continu[i][0]] + \ new_id_str[special_word_continu[i][1]:] ## 4단계 if new_id_str[0] == '.': new_id_str = new_id_str[1:] try: if new_id_str[-1] == '.': new_id_str = new_id_str[:-1] except IndexError: pass ## 5단계 if len(new_id_str) == 0: new_id_str = 'a' ## 6단계 if len(new_id_str) >= 16: new_id_str = new_id_str[:15] if new_id_str[-1] == '.': new_id_str = new_id_str[:-1] ## 7단계 while len(new_id_str) < 3: new_id_str = new_id_str + new_id_str[-1] return new_id_str | cs |
FeedBack
cjw.git@gmail.com
'알고리즘 > 소스코드' 카테고리의 다른 글
PROGRAMMERS 49994: 방문 길이 (0) | 2021.04.02 |
---|---|
PROGRAMMERS 68936: 쿼드압축 후 개수 세기 (0) | 2021.04.02 |
PROGRAMMERS 42628: 이중우선순위큐 (0) | 2021.03.24 |
KOREATECH 1111: 나무 쌓기 2 (0) | 2021.03.24 |
KOREATECH 1041: 최소 이동거리 구하기 - 2차원 (0) | 2021.03.02 |
댓글