매일 Algorithm

신재원·2023년 4월 14일
0

Algorithm

목록 보기
96/243

백준 1233번 (Bronze 2)

import java.util.Scanner;

public class problem308 {
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int a = in.nextInt(); // 첫번째 주사위
        int b = in.nextInt(); // 두번째 주사위
        int c = in.nextInt(); // 세번째 주사위

        // 합의 갯수를 저장할 배열, +1을 해주는 이유는 주사위가 1부터 시작
        int[] sum = new int[a + b + c + 1];

        for (int i = 1; i <= a; i++) {
            for (int j = 1; j <= b; j++) {
                for (int k = 1; k <= c; k++) {
                    sum[i + j + k]++; // 해당 합 인덱스 증가
                }
            }
        }

        int max = 0;
        int index = 0;

        for (int i = 0; i < sum.length; i++) {
            if (sum[i] > max) {
                max = sum[i];
                index = i;
            }
        }
        System.out.println(index);
    }

}

백준 1371번 (Bronze 2)

import java.util.Scanner;

public class problem309 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] arr = new int[26];


        // 공백이 입력되지 않은경우 계속 입력을 받는다.
        while (in.hasNextLine()) {
            String str = in.nextLine();
            for (int i = 0; i < str.length(); i++) {
                char ch = str.charAt(i);
                // 띄어쓰기가 입력될수 있음으로 검증
                if (ch >= 'a' && ch <= 'z') {
                    arr[ch - 'a']++;
                }
            }
        }


        int max = 0;

        for (int i = 0; i < arr.length; i++) {
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        for (int i = 0; i < arr.length; i++) {
            if (max == arr[i]) {
                System.out.print((char) (i + 'a'));
            }
        }

    }
}

백준 1408번 (Bronze 2)

public class problem310 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] a = in.nextLine().split(":");
        String[] b = in.nextLine().split(":");

        int nowH = Integer.parseInt(a[0]);
        int nowM = Integer.parseInt(a[1]);
        int nowS = Integer.parseInt(a[2]);

        int targetH = Integer.parseInt(b[0]);
        int targetM = Integer.parseInt(b[1]);
        int targetS = Integer.parseInt(b[2]);


        int diffH = targetH - nowH;
        int diffM = targetM - nowM;
        int diffS = targetS - nowS;

        // 음수 처리
        if (diffS < 0) {
            diffS += 60;
            diffM--;
        }
        if (diffM < 0) {
            diffM += 60;
            diffH--; // diffM이 음수라는것은 diffH에서 빼줘야된다.
        }
        if (diffH < 0) {
            diffH += 24;
        }

        // %02d : 2자리보다 작으면 '0'을 추가하여 2자리로 반환, 예 : 01
        System.out.printf("%02d:%02d:%02d", diffH, diffM, diffS);
    }
}

0개의 댓글