본문 바로가기

2018 카카오 블라인드 1차7

[프로그래머스] - 추석 트랙픽 (파이썬) 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.
[프로그래머스] - 캐시 (파이썬) from collections import deque def solution(cacheSize, cities): answer = 0 cache = deque() for city in cities: city = city.lower() if city in cache: answer += 1 for i in range(len(cache)): if cache[i] == city: cache.remove(city) break cache.append(city) else: answer += 5 if cacheSize != 0: if cache and len(cache) == cacheSize: cache.popleft() cache.append(city) return answer 2018 카카오 블라인드 1차 - 3번.. 2022. 1. 30.
[프로그래머스] - 다트 게임 (파이썬) def solution(dartResult): bonus = {'S': 1, 'D': 2, 'T': 3} option = ['*', '#'] dart = [] dartResult = dartResult.replace('10', 't') for i in range(len(dartResult)): if dartResult[i] == 't': dart.append('10') else: dart.append(dartResult[i]) result = [] number = 0 for x in dart: if x not in bonus and x not in option: result.append(number) number = 0 number += int(x) elif x in bonus: number = numb.. 2022. 1. 30.
[프로그래머스] - 비밀지도 (파이썬) def solution(n, arr1, arr2): answer = [] for i,j in zip(arr1,arr2): temp = bin(i|j)[2:] while len(temp) < n: temp = '0' + temp temp = temp.replace('0',' ') temp = temp.replace('1','#') answer.append(temp) return answer 2018 카카오 블라인드 1차 - 1번 1. arr1과 arr2를 비트연산자로 합해서 순수 2진수만 빼온다 (bin(i|j)[2:]) 2. n의 길이가 될 때 까지 앞의 빈공간에 '0'을 문자열에 더해준다 3. replace (0은 빈공간으로, 1은 #으로) 4. answer에 append 2022. 1. 30.