~2023.02/백준 문제풀이
[Python] 백준 2839번 : 설탕배달
https://www.acmicpc.net/problem/2839 2839번: 설탕 배달 상근이는 요즘 설탕공장에서 설탕을 배달하고 있다. 상근이는 지금 사탕가게에 설탕을 정확하게 N킬로그램을 배달해야 한다. 설탕공장에서 만드는 설탕은 봉지에 담겨져 있다. 봉지는 3킬로그 www.acmicpc.net [ 내 코드 ] n = int(input()) count = 0 while n >= 0: if n % 5 == 0: count += (n // 5) print(count) break n -= 3 count += 1 else: print(-1) 만약 n이 5의 배수면 봉지의 전체 개수는 n을 5로 나눈 몫이 되고 이 코드를 빠져나온다. 가령 n의 값이 10이었다면 10은 5의 배수이므로 count에 몫인 2를..
[Python] 백준 1092번 : 배
https://www.acmicpc.net/problem/1092 1092번: 배 첫째 줄에 N이 주어진다. N은 50보다 작거나 같은 자연수이다. 둘째 줄에는 각 크레인의 무게 제한이 주어진다. 이 값은 1,000,000보다 작거나 같다. 셋째 줄에는 박스의 수 M이 주어진다. M은 10,000보 www.acmicpc.net [ 내 코드 ] n = int(input()) n_list = list(map(int, input().split())) m = int(input()) m_list = list(map(int, input().split())) n_list.sort(reverse=True) m_list.sort(reverse=True) print(n_list) print(m_list) count = 0..
[Python] 백준 2012번 : 등수 매기기
https://www.acmicpc.net/problem/2012 2012번: 등수 매기기 첫째 줄에 자연수 N이 주어진다. (1 ≤ N ≤ 500,000) 둘째 줄부터 N개의 줄에 걸쳐 각 사람의 예상 등수가 순서대로 주어진다. 예상 등수는 500,000 이하의 자연수이다. www.acmicpc.net [ 내 코드 ] n = int(input()) real_list = [] expect_list = [] for i in range(n): real_list.append(i + 1) for i in range(n): expect_list.append(input()) expect_list.sort() sum = 0 for i in range(n): sum = sum + (int(real_list[i]) - ..
[Python] 백준 1439번 : 뒤집기
https://www.acmicpc.net/problem/1439 1439번: 뒤집기 다솜이는 0과 1로만 이루어진 문자열 S를 가지고 있다. 다솜이는 이 문자열 S에 있는 모든 숫자를 전부 같게 만들려고 한다. 다솜이가 할 수 있는 행동은 S에서 연속된 하나 이상의 숫자를 잡고 모 www.acmicpc.net [ 내 코드 ] num_list = list(input()) count = 0 for i in range(len(num_list)): if i == 0: first = num_list[i] elif i == 1: if first != num_list[1]: count += 1 else: if num_list[i] != num_list[i-1]: count += 1 if count == 1: pri..
[Python] 백준 5585번 : 거스름돈
https://www.acmicpc.net/problem/5585 5585번: 거스름돈 타로는 자주 JOI잡화점에서 물건을 산다. JOI잡화점에는 잔돈으로 500엔, 100엔, 50엔, 10엔, 5엔, 1엔이 충분히 있고, 언제나 거스름돈 개수가 가장 적게 잔돈을 준다. 타로가 JOI잡화점에서 물건을 사 www.acmicpc.net [ 나의 답 ] value = int(input()) coin_list = [500, 100, 50, 10, 5, 1] count = 0 left_coin = 1000 - value for i in coin_list: num = left_coin // i count += num left_coin -= num * i print(count) [ 클린 코드] changes = 10..
[JAVA] 백준 단계별로 풀어보기_5단계(1차원 배열)
10818번: 최소, 최대 import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] intArray = new int[N]; for (int i = 0; i < N; i++) { intArray[i] = sc.nextInt(); } Arrays.sort(intArray); System.out.print(intArray[0] + " " + intArray[N - 1]); } } for문을 작성하는데 까진 성공했지만 최대, 최소 찾는 기능에 대해서는 배..
[JAVA] 백준 단계별로 풀어보기_4단계(while문)
10952번: A+B-5 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int A = sc.nextInt(); int B = sc.nextInt(); if (A == 0 && B == 0) { break; } System.out.println(A + B); } } } while 다음의 조건문에 A == 0 && B == 0 을 넣으려는 잘못된 시도를 반복하다가 어찌저찌 해결! 10951번: A+B-4 import java.util.Scanner; public class Main { public static..
[JAVA] 백준 단계별로 풀어보기_3단계(for문)
2739번: 구구단 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); for (int i = 1; i < 10; i++) { System.out.println(num + " * " + i + " = " + num * i); }; } } 10950번: A+B-3 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num ..
[JAVA] 백준 단계별로 풀어보기_3단계(for문)
2739번: 구구단 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); for (int i = 1; i < 10; i++) { System.out.println(num + " * " + i + " = " + num * i); }; } } 10950번: A+B-3 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num ..