본문 바로가기

2019 카카오 블라인드7

[프로그래머스] - 블록게임 (파이썬) # 블록게임 import copy dx = [[0, 0, 0, 1, 1, 1], [0, 0, 1, 1, 2, 2]] dy = [[0, 1, 2, 0, 1, 2], [0, 1, 0, 1, 0, 1]] answer = 0 def solution(board): N = len(board) global answer while True: if not drop_block(board): break return answer def drop_block(arr): N = len(arr) for j in range(N): for i in range(N): if arr[i][j] == -1: continue if arr[i][j] != 0: break arr[i][j] = -1 return check(arr) def check.. 2022. 2. 15.
[프로그래머스] - 매칭점수 (파이썬) # 매칭점수 from operator import indexOf import re def solution(word, pages): pages_info = [] for i, page in enumerate(pages): temp = list(seperate(word, page)) + [0, i] pages_info.append(temp) for page in pages_info: url, basic_score, link_num, links, link_score, index = page for link in links: for page in pages_info: if link == page[0]: page[4] += basic_score / link_num pages_info.sort(key=lambda x.. 2022. 2. 15.
[프로그래머스] - 길 찾기 게임 (파이썬) import sys sys.setrecursionlimit(10**3) class Node: def __init__(self, index, x, y): self.index = index self.x = x self.y = y self.left = None self.right = None class Tree: def __init__(self, index, x, y): self.head = Node(index, x, y) def insert(self, index, x, y): curr = self.head while True: if curr.x > x: if curr.left == None: curr.left = Node(index, x, y) break else: curr = curr.left else: .. 2022. 2. 15.
[프로그래머스] - 무지의 먹방 라이브 (파이썬) # 무지의 먹방 라이브 import heapq def solution(food_times, K): answer = -1 food = [] for i in range(len(food_times)): heapq.heappush(food, (food_times[i], i+1)) prev = 0 l = len(food) while food: temp = (food[0][0] - prev) * l if K >= temp: K -= temp prev, _ = heapq.heappop(food) l -= 1 else: index = K % l food.sort(key=lambda x: x[1]) answer = food[index][1] break return answer 2019 카카오 블라인드 - 4번 1. fo.. 2022. 2. 15.
[프로그래머스] - 후보키 (파이썬) # 후보키 from itertools import combinations def solution(relation): answer = 0 N, M = len(relation), len(relation[0]) arr = [] for i in range(1, M+1): arr.extend(combinations(range(M), i)) total = [] for x in arr: isOK = True for t in total: for k in t: if k in ''.join(map(str, x)): isOK = False else: isOK = True break if not isOK: break if isOK: if check(x, relation): total.append(list(map(str, x).. 2022. 2. 15.
[프로그래머스] - 실패율 (파이썬) # 실패율 def solution(N, stages): answer = [[i, 0] for i in range(N+2)] arrive = [0] * (N+2) for x in stages: arrive[x-1] += 1 for i in range(len(arrive)-1, 0, -1): arrive[i-1] += arrive[i] for i in range(1, len(arrive)): if arrive[i-1] != 0: answer[i][1] = (arrive[i-1] - arrive[i]) / arrive[i-1] answer.sort(key=lambda x: -x[1]) result = [] for i, x in answer: if i != 0 and i != len(answer)-1: resu.. 2022. 2. 15.
[프로그래머스] - 오픈채팅방 (파이썬) # 오픈채팅방 uuid = dict() id_name = dict() def solution(record): answer = [] i = 0 for str in record: if str.split()[0] == 'Leave': type, id = str.split() name = id_name[id] answer.append([name, '님이 나갔습니다.']) uuid[id].append(i) i += 1 else: type, id, name = str.split() id_name[id] = name if type == 'Enter': if uuid.get(id): id_name[id] = name change(id, name, answer) uuid[id].append(i) else: uuid[id.. 2022. 2. 15.