내가 까먹을까봐 만든 블로그

전체 글

Coding Test

[Python] 백준 11004 - 세준세비

문제https://www.acmicpc.net/problem/1524 해설정렬을 이용하는 문제였다. 그런데 입력 방식에 대한 불필요한 조건들이 있어 헷갈릴 수 있다. 알고리즘 테스트에서 알고리즘과 무관한 조건도 중요하게 여겨야 한다는 점 때문에 수준이 낮은 문제라 생각된다. def solution(case): for _ in range(case): input() # 입력 구분 n, m = map(int, input().split()) sj_soldiers = sorted(list(map(int, input().split()))) sb_soldiers = sorted(list(map(int, input().split()))) while s..

Coding Test

[Python] leetcode 2231 - Largest Number After Digit Swaps by Parity

문제https://leetcode.com/problems/largest-number-after-digit-swaps-by-parity/description/ 해설정렬을 활용하여 해결할 수 있는 문제였다. class Solution: def largestInteger(self, num: int) -> int: num_str = str(num) odd_digits = sorted([d for d in num_str if int(d) % 2 == 1], reverse=True) even_digits = sorted([d for d in num_str if int(d) % 2 == 0], reverse=True) result = [] for d..

Coding Test

[Python] leetcode 506 - Relative Ranks

문제https://leetcode.com/problems/relative-ranks/ 해설정렬을 활용하는 문제였다. import copyclass Solution: def findRelativeRanks(self, score: List[int]) -> List[str]: prize = { 0: "Gold Medal", 1: "Silver Medal", 2: "Bronze Medal", } sorted_score = copy.deepcopy(score) sorted_score.sort(reverse=True) result = [] for r in [sorted_scor..

Coding Test

[Python] 백준 11557 - Yangjojang of The Year

문제https://www.acmicpc.net/problem/11557 해설해시 맵을 이용하여 해결하였다. def solution(n): for _ in range(n): univ_cnt = int(input()) univ_map = dict() for _ in range(univ_cnt): univ, bottle = input().split() bottle = int(bottle) if univ in univ_map: univ_map[univ] += bottle else: univ_map[univ] = bottle..

Coding Test

[Python] 프로그래머스 - 다리를 지나는 트럭

문제https://school.programmers.co.kr/learn/courses/30/lessons/42583 프로그래머스SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프programmers.co.kr 해설두개의 큐(현재 코드에선 리스트로 구현)를 활용하여 해결할 수 있는 문제였다. def solution(bridge_length, weight, truck_weights): second = 0 on_bridge_car = [] on_bridge_sec = [] while truck_weights or on_bridge_car: second += 1 pass_state = False ..

Coding Test

[Python] 백준 11004 - K번째 수

문제https://www.acmicpc.net/problem/11004 해설최소 힙을 사용하는 문제였다. import heapqdef solution(target, heap): heapq.heapify(heap) for _ in range(target-1): heapq.heappop(heap) return heap[0]n, k = map(int, input().split())order = list(map(int, input().split()))print(solution(k, order))

AlienCoder
외부 저장소
loading