Blog blog = new Korea()

알고리즘

[백준] 4344 평균은넘겠지 (Java)

God Korea 2022. 7. 27. 00:10
728x90

import java.io.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {

        // 백준 4344: "평균은 넘겠지"
        Scanner sc = new Scanner(System.in);

        //입력 변수
        int testcase = sc.nextInt(); //테스트케이스 수
        int[] arr;

        for(int i = 0; i < testcase; i++) {
            int c = sc.nextInt(); // 테스트케이스 수에 대입되는 학생의 수
            arr = new int[c]; // 학생 수만큼의 배열을 미리 초기화

            double sum = 0;

            for (int j = 0; j < c; j++) {
                int score = sc.nextInt(); // 점수 입력받기
                arr[j] = score; // 각 학생 수에 맞는 점수 배열에 점수를 대입
                sum += score; // 점수들의 합
            }

            double avg = (sum / c);
            double count = 0;

            // 평균 이상의 학생 수 구하기
            for(int j = 0; j < arr.length; j++) {
                if(arr[j] >avg) {
                    count += 1;
                }
            }

            System.out.printf("%.3f%%\n", (count/c) * 100);
        }

    }
}
728x90