BOJ 179

백준 2609번 최대공약수와 최소공배수 Swift

https://www.acmicpc.net/problem/2609 2609번: 최대공약수와 최소공배수 첫째 줄에는 입력으로 주어진 두 수의 최대공약수를, 둘째 줄에는 입력으로 주어진 두 수의 최소 공배수를 출력한다. www.acmicpc.net 내 코드 // 유클리드 호제법 func gcd(_ a: Int, _ b: Int) -> Int { var a = a var b = b while b != 0 { let temp = b b = a % b a = temp } return a } func lcm(_ a: Int, _ b: Int, gcd: Int) -> Int { return (a * b / gcd) } let input = readLine()!.split(separator: " ").map { Int..

BOJ/Swift 2024.04.18

[프로그래머스] 해시 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/42576 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 코드 from collections import defaultdict def solution(participant, completion): hash_table = defaultdict(int) for i in participant: hash_table[i] += 1 for i in completion: hash_table[i] -= 1 if hash_table[i] == 0: del hash_..

BOJ/Python 2024.03.23

백준 7568번 덩치 파이썬

https://www.acmicpc.net/problem/7568 7568번: 덩치 우리는 사람의 덩치를 키와 몸무게, 이 두 개의 값으로 표현하여 그 등수를 매겨보려고 한다. 어떤 사람의 몸무게가 x kg이고 키가 y cm라면 이 사람의 덩치는 (x, y)로 표시된다. 두 사람 A 와 B의 덩 www.acmicpc.net 내 코드 big = [] result = [] N = int(input()) for i in range(N): x, y = list(map(int, input().split())) big.append((x, y)) for i in range(N): cnt = 1 for j in range(N): if big[i][0] < big[j][0] and big[i][1] < big[j][1]..

BOJ/Python 2024.03.22

백준 14502번 연구소 파이썬 BFS

https://www.acmicpc.net/problem/14502 14502번: 연구소인체에 치명적인 바이러스를 연구하던 연구소에서 바이러스가 유출되었다. 다행히 바이러스는 아직 퍼지지 않았고, 바이러스의 확산을 막기 위해서 연구소에 벽을 세우려고 한다. 연구소는 크www.acmicpc.net 내 답안import sys import copy from collections import deque input = sys.stdin.readline N, M = map(int, input().split()) lab = [list(map(int, input().split())) for _ in range(N)] dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] def find_spaces(lab..

BOJ/Python 2024.03.20

백준 14719번 빗물 파이썬

https://www.acmicpc.net/problem/14719 14719번: 빗물 첫 번째 줄에는 2차원 세계의 세로 길이 H과 2차원 세계의 가로 길이 W가 주어진다. (1 ≤ H, W ≤ 500) 두 번째 줄에는 블록이 쌓인 높이를 의미하는 0이상 H이하의 정수가 2차원 세계의 맨 왼쪽 위치 www.acmicpc.net 내 코드 h, w = map(int, input().split()) blocks = list(map(int, input().split())) result = 0 for i in range(1, w-1): left_max = max(blocks[:i]) right_max = max(blocks[i+1:]) standard = min(left_max, right_max) depth ..

BOJ/Python 2024.03.19

백준 1966번 프린터 큐 파이썬

https://www.acmicpc.net/problem/1966 1966번: 프린터 큐 여러분도 알다시피 여러분의 프린터 기기는 여러분이 인쇄하고자 하는 문서를 인쇄 명령을 받은 ‘순서대로’, 즉 먼저 요청된 것을 먼저 인쇄한다. 여러 개의 문서가 쌓인다면 Queue 자료구조에 www.acmicpc.net 내 답안 from collections import deque N = int(input()) for i in range(N): N, M = map(int, input().split()) priority = deque(list(map(int, input().split()))) ind = deque([i for i in range(N)]) cnt = 0 while priority: m = max(prio..

BOJ/Python 2024.03.08

[프로그래머스] 의상 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/42578 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 답안 from collections import defaultdict def solution(clothes): dic = defaultdict(int) answer = 1 for _, y in clothes: dic[y] += 1 for _, j in dic.items(): answer *= (j+1) return answer-1 Review 이 문제는 보자마자 구현이 아닌 수학적으로 접근해야..

BOJ/Python 2024.02.12

[프로그래머스] 키패드 누르기 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/67256 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 보기 더보기 내 코드 def judge(start, end): keypad = { '1': (0, 0), '2': (0, 1), '3': (0, 2), '4': (1, 0), '5': (1, 1), '6': (1, 2), '7': (2, 0), '8': (2, 1), '9': (2, 2), '*': (3, 0), '0': (3, 1), '#': (3, 2) } start_distance = ..

BOJ/Python 2023.11.24

[프로그래머스] 신고 결과 받기 파이썬

https://school.programmers.co.kr/learn/courses/30/lessons/92334 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 보기 더보기 내 코드 from collections import defaultdict def solution(id_list, report, k): answer = [0] * len(id_list) report_count = defaultdict(int) for i in set(report): report_count[i.split()[1]] += 1 filtered_set = {key for ..

BOJ/Python 2023.11.20