핑구

[백준/JAVA] 4344번 : 평균은 넘겠지 본문

카테고리 없음

[백준/JAVA] 4344번 : 평균은 넘겠지

코딩 펭귄 2021. 9. 7. 13:41

https://www.acmicpc.net/problem/4344

 

4344번: 평균은 넘겠지

대학생 새내기들의 90%는 자신이 반에서 평균은 넘는다고 생각한다. 당신은 그들에게 슬픈 진실을 알려줘야 한다.

www.acmicpc.net

 

 

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] studentNum = new int[num];
		double[] avg = new double[num];
		
		for(int i = 0; i < studentNum.length; i++) {

			studentNum[i] = sc.nextInt();
			int[] studentScore = new int[studentNum[i]];
			
			for(int j = 0; j < studentScore.length; j++) {
				studentScore[j] = sc.nextInt();
				avg[i] += studentScore[j];
			}
			avg[i] = avg[i] / studentNum[i];
			int count = 0;
			
			for(int k = 0; k < studentScore.length; k++) {
				if(avg[i] < studentScore[k]) {
					count++;
				}
			}
			avg[i] = 100.0 / studentNum[i] * count;
		}
		
		for(int i = 0; i < avg.length; i++) {
			System.out.printf("%.3f%%%n", avg[i]);
		}
	}
}