전체 글

전체 글

    백준 1715. 카드 정렬하기(JAVA)

    백준 1715. 카드 정렬하기(JAVA)

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.PriorityQueue; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int card_case = Integer.parseInt(br.readLine()); PriorityQueue pq = new PriorityQueue(); int result = 0; for(int i = 1 ..

    백준 1927. 최소 힙(JAVA)

    백준 1927. 최소 힙(JAVA)

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.PriorityQueue; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); int num_cnt = Integer.parseInt(br.readLine()); PriorityQueue pq= new PriorityQueue(); for(int i = 0 ; i < num_cnt ; i+..

    백준 10773. 제로(JAVA)

    백준 10773. 제로(JAVA)

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Stack; public class B10733 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int input_num = Integer.parseInt(br.readLine()); Stack sta = new Stack(); int result = 0; for(int i = 0 ; i < input_num ; i++..

    백준 10828. 스택(JAVA)

    백준 10828. 스택(JAVA)

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Stack; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stringTokenizer; int order_num = Integer.parseInt(br.readLine()); // String을 ..

    백준 8958. OX퀴즈(JAVA)

    백준 8958. OX퀴즈(JAVA)

    import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String arr = new String(); int test_case = sc.nextInt(); int sum = 1; // 정답일 경우 result와 합하기 위해 선언. int result = 0; for(int i = 0 ; i < test_case ; i++) { arr = sc.next(); for(int j = 0 ; j < arr.length(); j++) { char ch = arr.charAt(j); if(ch == 'O') { // 'O'일 때 result += s..

    백준 11399. ATM(JAVA)

    백준 11399. ATM(JAVA)

    public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int[] arr = new int[num]; for(int i = 0 ; i < num ; i++) { arr[i] = sc.nextInt(); } Arrays.sort(arr); int pre_sum = 0; int sum = 0; for(int i = 0 ; i < num ; i++) { pre_sum += arr[i]; // pre_sum = pre_sum + arr[i]; sum += pre_sum; // sum = sum + pre_sum } sc.close(); System.o..

    백준 2839. 설탕 배달(JAVA)

    백준 2839. 설탕 배달(JAVA)

    import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int weight = sc.nextInt(); int cnt = 0; while(true) { if(weight % 5 == 0) { cnt += weight/5; System.out.println(cnt); return; }else { weight -= 3; cnt++; } if( weight < 0) { System.out.println(-1); return; } } } } 이 문제의 키포인트는 가장 적은 개수로 배달을 해야 한다는 것이다. 예를 들어, 15kg를 배달할 경우 3k..

    백준 2490. 윷놀이(JAVA)

    백준 2490. 윷놀이(JAVA)

    import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int sum = 0 ; for(int i = 0 ; i < 3 ; i++ ) { // 테스트 케이스를 3번 수행하기 위해. for(int j = 0 ; j < 4 ; j++) { int num = sc.nextInt(); sum += num; // sum = sum + num } if(sum == 4) { System.out.println("E"); // 모 }else if( sum == 3) { System.out.println("A"); // 도 }else if( sum == 2)..

    백준 1009. 분산처리(JAVA)

    백준 1009. 분산처리(JAVA)

    import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i = 0 ; i < t ; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = 1; for(int j = 0 ; j < b ; j++) { c = (a * c) % 10; if( c == 0) { c = 10; } } System.out.println(c); } sc.close(); } } 여기서 키포인트는 a^b를 구하는 것이다. a^b를 구하고 10으로 나눈 뒤 나머지를 통해..