Study/algorithm

백준 자바 알고리즘 [4344 : 평균은 넘겠지]

프로그래멍 2020. 5. 3. 19:32

 Scanner sc = new Scanner(System.in);
        int test = sc.nextInt(); //케이스 수
        int num = sc.nextInt();  //학생 수
        int[] s = new int[num];
        double avg = 0; //평균
        for (int i = 0; i < test; i++) {
            double total = 0;
            int avgS = 0;
            for (int j = 0; j < num; j++) {
                s[j] = sc.nextInt();
                total += s[j];    //합계 구하기
            }
            avg = total / num; //평균

            for (int j = 0; j < num; j++) {
                if (s[j]>avg){
                    avgS++;
                }
            }
            
            System.out.printf("%.3f",100.0*avgS/num);

        }

        sc.close();