본문 바로가기

Algorithm/프로그래머스101

[프로그래머스] - 파일명 정렬 (파이썬) number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] def solution(files): arr = [['' for _ in range(3)] for _ in range(len(files))] for file in range(len(files)): do = False slice = 0 for x in range(len(files[file])): if files[file][x] in number: if not do: arr[file][0] = files[file][:x] slice = x do = True if x == len(files[file])-1: arr[file][1] = files[file][x:] if x == len(files[file].. 2022. 2. 6.
[프로그래머스] - 압축 (파이썬) alpha = {'A':1,'B':2,'C':3,'D':4,'E':5,'F':6,'G':7,'H':8, 'I':9,'J':10,'K':11,'L':12,'M':13,'N':14,'O':15,'P':16,'Q':17, 'R':18,'S':19,'T':20,'U':21,'V':22,'W':23,'X':24,'Y':25,'Z':26} def solution(msg): answer = [] left, right = 0, 1 start = 0 while right 2022. 2. 6.
[프로그래머스] - n진수 게임 (파이썬) alpha = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'} def solution(n, t, m, p): all = '' count = 0 needs = p for _ in range(t-1): needs += m while True: if len(all) > needs: break all_temp = '' temp = count while True: k = temp % n if k in alpha: k = alpha[k] all_temp = str(k) + all_temp if temp // n != 0: temp = temp // n else: break all += all_temp count += 1 answer = '' for i in rang.. 2022. 2. 6.
[프로그래머스] - 추석 트랙픽 (파이썬) def solution(lines): start = [] end = [] for log in lines: time = log.split() start.append(get_start_second(time[1], time[2])) end.append(get_second(time[1])) answer = 0 for i in range(len(end)): result = 0 for j in range(i, len(start)): if end[i] + 1000 > start[j]: result += 1 answer = max(answer, result) return answer def get_second(time): temp, milisecond = time.split('.') hour, minute, secon.. 2022. 1. 30.
[프로그래머스] - 프렌즈4블록 (파이썬) from collections import deque dx = [0, 1, 1] dy = [1, 0, 1] break_block_list = [] def solution(n, m, board): answer = 0 board_t = [[0] * m for _ in range(n)] for i in range(n): for j in range(m): board_t[i][j] = board[i][j] while True: for i in range(n): for j in range(m): if board_t[i][j] != 0: isFour(i, j, board_t, n, m) answer += break_block(board_t, n, m) if not move(board_t, n, m,): break r.. 2022. 1. 30.
[프로그래머스] - 뉴스 클러스터링 (파이썬) def solution(str1, str2): str1 = str1.lower() str2 = str2.lower() one = [str1[i:i+2] for i in range(len(str1)-1) if str1[i:i+2].isalpha()] two = [str2[i:i+2] for i in range(len(str2)-1) if str2[i:i+2].isalpha()] print(one) print(two) one_and_two = set(one) & set(two) one_or_two = set(one) | set(two) and_num = 0 or_num = 0 for i in one_and_two: and_num += min(one.count(i), two.count(i)) for i in .. 2022. 1. 30.
[프로그래머스] - 셔틀버스 (파이썬) def solution(n, t, m, timetable): crew_time = [] for time in timetable: crew_time.append(get_time(time)) crew_time.sort() bus_time = [] for i in range(n): bus_time.append(get_bus_time(t, i)) my_time = 0 temp = 0 for bus in bus_time: my_time = bus max_people = m for i in range(temp, len(crew_time)): if bus >= crew_time[i] and max_people: max_people -= 1 temp += 1 if max_people == 0: my_time = cre.. 2022. 1. 30.