Algorithm
백준 2577 (숫자의 개수)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int arr[] = new int[10]; int sum = scan.nextInt()*scan.nextInt()*scan.nextInt(); // sum = A * B * C while(sum!=0) { // sum == 0이 될때까지 반복 arr[(sum%10)]++; // ex) sum%10 == 3일 경우 arr[3]++ sum /= 10; // sum = sum / 10 } for(..
백준 2562 (최댓값)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int[] arr = new int[9]; int max = 0; int maxIndex = 0; for(int i=0; imax) { max = arr[i]; maxIndex = i+1; // 최대값이 몇번째 자리인지(인덱스 번호 + 1) } } System.out.println(max); System.out.println(maxIndex); } } Colored by Col..
백준 10818 (최소, 최대)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 import java.util.Arrays; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { // 입출력 예외처리 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = ..
백준 1110 (더하기 사이클)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int x, y, sum, count = 0; int N = scan.nextInt(); int temp = N; // N 대신에 반복문에서 사용할 임시 변수 while(true) { x = temp / 10; y = temp % 10; sum = x + y; temp = (y *= 10) + (sum % 10); count++; if(temp == N) { break; ..
백준 2439 (별 찍기 - 2)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int a = scan.nextInt(); // 몇 a번째 줄까지 출력할지 입력 for (int i=1; i0; j--) { // a-i 만큼 공백 출력 System.out.print(" "); } for (int k=1; k
백준 15552 (빠른 A+B)
1234567891011121314151617181920212223242526272829import java.io.*;import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { // 입출력 예외처리 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // 버퍼를 이용한 입력 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); // 버퍼를 이용한 출력 StringTokenizer st; // 하나의 문..
백준 2480 (주사위 세개)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); if(a==b && b==c && c==a) { // 같은 눈이 3개일 경우 System.out.println(10000 + a * 1000); } else if(a==b || b==c)..
백준 2525 (오븐 시계)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int hour = scan.nextInt(); // 시간 int min = scan.nextInt(); // 분 int oven =scan.nextInt(); // 오븐이 걸리는 시간(분) if(min+oven>=60) { // 60분 이상일경우 hour += (min+oven) / 60; // 나눈 몫을 hour에 +한다 min = (min+oven) % 60; // ..