[백준] 평균은 넘겠지

업데이트:

백준 4344. 평균은 넘겠지

백준 4344번 링크

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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int C = Integer.parseInt(br.readLine());
		for(int i=0; i<C; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			int N = Integer.parseInt(st.nextToken());
			int[] score = new int[N];
			int sum = 0; //평균을 구할때 필요
			double avg = 0; //평균
			
			//학생 점수 저장하기
			for (int j=0; j<N; j++) {
				score[j] = Integer.parseInt(st.nextToken());
				sum += score[j];
				
			}
			//평균 구하기
			avg = sum / N;

			//평균을 바탕으로 % 구하기
			int cnt = 0;
			for (int j=0; j<N; j++) {
				if (score[j] > avg) {
					cnt++;
				}
			}
			
			double per = (double)cnt / (double)N;
			System.out.print(String.format("%.3f", per * 100));
			System.out.println("%");
		}
	}
}

댓글남기기