전체 글62 백준 2231번 분해합 분해합은 어떤 자연수 N이 주어졌을 때, 생성자 숫자를 구하는 문제다. 반대로 분해합은 어떤 자연수 N과 N을 이루는 각 자리수의 합을 의미한다. 예를 들어 N = 245 라면 분해합은 245 + (2 + 4 + 5) = 256 이다. 이 문제는 숫자를 증가시키며 분해합을 계산하고, 그 계산값이 N과 일치하는 숫자를 출력해 풀이하였다. import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int ans = func(N); System.out.println(.. 2023. 3. 13. 백준 2798번 블랙잭 블랙잭은 주어진 몇 장의 카드 중에서 3장을 조합해 특정 최대값(M)을 넘지 않으면서 가장 근접한 카드합을 출력하는 문제다. 3중 반복문(for)을 사용해 문제를 해결하였다. 중복된 카드 뽑기를 허용하지 않으므로, 각 반복문의 인덱싱에 주의하자. import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int M = in.nextInt(); int[] cards = new int[N]; for (int i = 0; i < N; i++) { cards[i] = .. 2023. 3. 13. 백준 1436번 영화감독 숌 영화감독 숀은 666이 들어간 N번째 숫자를 찾는 문제다. N = 1, output = 666 N = 2, output = 1666 ... N = 6, output = 5666 N = 7, output = 6660 N = 8, output = 6661 ... N = 16, output = 6669 N = 17, output = 7666 ... 666부터 시작하여 숫자를 증가시키며 무차별 대입 방법을 활용해 풀이했다. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int cnt = 1; int .. 2023. 3. 11. 백준 1934번 최소공배수 주어진 두 숫자의 최소공배수를 구하는 문제다. 이 문제는 두 숫자의 최대공약수를 구하는 대표적인 알고리즘인 유클리드 호제법을 활용해 풀이하였다. ※ 최소공배수를 구하는 문제이며, 최소공배수는 [숫자1 x 숫자2 / 최대공약수] 로 계산할 수 있다. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int i = 0; i < T; i++) { int A = in.nextInt(); int B = in.nextInt(); int gcd = calcGcd(B, A); // 최대공약수 int l.. 2023. 3. 11. 이전 1 ··· 9 10 11 12 13 14 15 16 다음