Algorithm245 [프로그래머스] - 뉴스 클러스터링 (파이썬) 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. [백준] 1202번 - 보석 도둑 (파이썬) # 보석 도둑 import sys import heapq input = sys.stdin.readline N, K = map(int, input().split()) gem = [] for _ in range(N): weight, cost = map(int, input().split()) heapq.heappush(gem, (weight, cost)) bags = [] for _ in range(K): w = int(input()) bags.append(w) bags.sort() result = 0 temp = [] for bag_weight in bags: while gem: if bag_weight >= gem[0][0]: weight, cost = heapq.heappop(gem) heapq.heap.. 2022. 1. 30. [백준] 17135번 - 캐슬 디펜스 (파이썬) # 캐슬 디펜스 import copy import sys input = sys.stdin.readline MAX = sys.maxsize N, M, D = map(int, input().split()) arr = [] enemy = [] for i in range(N): arr.append(list(map(int, input().split()))) for j in range(M): if arr[i][j] == 1: enemy.append([i, j]) enemy.sort(key=lambda x: x[1] arch = [] target = [] result = 0 def archPositon(count, k): if count == 3: temp = copy.deepcopy(arr) tenemy = cop.. 2022. 1. 30. 이전 1 ··· 27 28 29 30 31 32 33 ··· 35 다음