매일 Algorithm

신재원·2023년 2월 3일
0

Algorithm

목록 보기
26/243

백준 4344번 (bronze1)

import java.util.Scanner;

public class problem29 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int [] array;
        int size = in.nextInt();

        for (int i = 0; i < size; i++) {
            int student = in.nextInt();
            array = new int[student];

            double sum = 0;

            for (int j = 0; j < student; j++) {
                int record = in.nextInt();
                array[j] = record;
                sum += record; // 성적 누적
            }
            double temp = (sum/student);
            double count = 0; // 평균 이상인 학생수

            for (int j = 0; j < student; j++) {
                if(array[j] > temp){
                    count ++;
                }
            }
            // 소수 3자리 출력
            System.out.printf("%.3f%%\n",(count/student)*100);
        }


    }
}

백준 1032 (bronze1)

import java.util.Scanner;

public class problem30 {
    public static void main(String[] args) {
        // 첫번째 입력받은 문자열이랑 비교한다.
        Scanner in = new Scanner(System.in);
        int size = in.nextInt();

        char[] cmd = in.next().toCharArray();
        // size - 1 하는 이유는 먼저 입력받은 cmd 하나를 제외해주기 위해
        for (int i = 0; i < size - 1; i++) {
            // size 정수 만큼 cmd 입력
            char[] cmdList = in.next().toCharArray();
            
            // 입력받은 cmd의 length만큼 검증
            for (int j = 0; j < cmd.length; j++) {
                if(cmd[j] != cmdList[j]){
                    cmd[j] = '?';
                }
            }
        }
        System.out.println(cmd);
    }
}

백준 1145번 (bronze 1)

import java.util.Scanner;

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

        Scanner in = new Scanner(System.in);

        int[] array = new int[5];
        int div = 1;
        int count = 0; // 3개 이상의 수로 나누어 질경우를 검증

        for (int i = 0; i < array.length; i++) {
            array[i] = in.nextInt();
        }

        while (true) {
            for (int i = 0; i < array.length; i++) {
                // div를 증가시켜 배열의 수로 나누어지는지 검증
                if (div % array[i] == 0) {
                    count++;
                }
            }
            if (count >= 3) {
                break;
            }
            // 초기화를 해주지 않으면 div = 1에서 다 걸려들어간다.
            count = 0;
            div++;
        }
        System.out.println(div);
        in.close();
    }
}

0개의 댓글