본문 바로가기

알고리즘 풀이(JAVA)/백준

(53)
[백준] 문제번호 10811(바구니 뒤집기)(브론즈 2)(java) [문제] [답안] import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] arr = new int[n]; int[] arr2 = new int[n]; for (int k = 0; k < n; k++) { arr[k] = k + 1; arr2[k] = k + 1; } for (int k = 0; k < m; k++) { int i = sc.nextInt(); int j = sc.nextInt(); int tmp = j; for (int r = i - 1;..
[백준] 문제번호 10813(공 바꾸기)(브론즈 2)(java) [문제] [답안] import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] arr = new int[n]; for (int k = 0; k < n; k++) { arr[k] = k + 1; } for (int k = 0; k < m; k++) { int i = sc.nextInt(); int j = sc.nextInt(); int tmp = arr[i - 1]; arr[i - 1] = arr[j - 1]; arr[j - 1] = tmp; } for (in..
[백준] 문제번호 10810(공 넣기)(브론즈 3)(java) [문제] [답안] 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 m = sc.nextInt(); // 골을 넣는 방법 int[] answer = new int[n]; for (int a = 0; a < m; a++) { int i = sc.nextInt(); int j = sc.nextInt(); int k = sc.nextInt(); for (int l = i - 1; l < j; l++) { answer[l] = k; ..
[백준] 문제번호 10821(정수의 개수)(브론즈 2)(java) [문제] [답안] import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); String[] str = s.split(","); System.out.println(str.length); sc.close(); } } 출처 https://www.acmicpc.net/problem/10821 10821번: 정수의 개수 숫자와 콤마로만 이루어진 문자열 S가 주어진다. 이때, S에 포함되어있는 정수의 개수를 구하는 프로그램을 작성하시오. S의 첫 문자와 마지막 문자는 항상 숫자이고, 콤마는 연속해서 주어지지 www..
[백준] 문제번호 5585(거스름돈)(브론즈 2)(java) [문제] [답안] import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int price = sc.nextInt(); int[] coins = {500, 100, 50, 10, 5, 1}; int n = 1000 - price; int cnt = 0; for (int i : coins) { if (n / i != 0) { cnt += n / i; n %= i; } } System.out.println(cnt); } } https://www.acmicpc.net/problem/5585 5585번: 거스름돈 타로는 자주 JOI잡화점에서 물건을..
[백준] 문제번호 5086(배수와 약수)(브론즈 3)(java) [문제] [답안] 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; if (b % a == 0) { System.out.println("factor"); } else if (a % b == 0) { System.out.println("multiple"); } else { System.out.println("neither"); } } sc.close(); } } 출처 https://..
[백준] 문제번호 10866(덱)(실버 4)(java) [문제] [답안] import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.ArrayDeque; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ArrayDeque dq = new ArrayDeque(); // 덱 선언 StringBuilder sb = new StringBuilder(); int N = Integer.parseInt(br.re..
[백준] 문제번호 11653(소인수분해)(브론즈 1)(java) [문제] [답안] import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); for (int i = 2; i