본문 바로가기

백준

백준 4344 - 평균은 넘겠지

728x90

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.Scanner;
 
public class B4344 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int testCase = scanner.nextInt();
        double count = 0;
        double avg = 0;
        double sum = 0;
        double percent = 0;
        
        for (int i = 0; i < testCase; i++) {
            //학생수
            int N = scanner.nextInt();
            //학생 수 만큼의 크기를 가지는 점수 배열
            double[] scoreArry = new double[N];
            
            for (int j = 0; j < N; j++) {
                //점수 입력
                double score = scanner.nextDouble();
                //배열에 각 점수 저장
                scoreArry[j] = score;
                sum+=scoreArry[j];
            }            
            avg = sum/N;
            
            for (int j = 0; j < N; j++) {
                //점수의 평균보다 높은 점수 카운트
                if (scoreArry[j]>avg) {
                    count++;
                }
            }
            //비율 구하는 식
            percent = count/N*100;
            //소수점 3자리까지 반올림하도록 String.format사용
            System.out.println(String.format("%.3f", percent)+"%");
            
            //모든 정보 초기화
            for (int j = 0; j < N; j++) {
                scoreArry[j] = 0;
            }
            percent = 0;
            count =0;
            sum=0;
            avg=0;
        }
        scanner.close();
    }
}
 
cs
728x90

'백준' 카테고리의 다른 글

백준 11654 - 아스키 코드  (0) 2022.05.16
백준 2798 - 블랙잭  (0) 2022.05.16
백준 8958 - OX퀴즈  (0) 2022.05.11
백준 1546 - 평균  (0) 2022.05.11
백준 3052 - 나머지  (0) 2022.05.11