본문 바로가기
Coding Test/백준

[백준 4344번 - java] 평균은 넘겠지

by olli2 2021. 11. 12.

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

내 답안

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int C = s.nextInt();
		for (int i=0; i<C; i++) {
			
		int N = s.nextInt();
		int[] score = new int[N];
		float total = 0;
		float avg = 0;
		float cnt = 0;
		for (int j=0; j<N; j++) {
			score[j] = s.nextInt();
			total += score[j];
		}
		avg = total/N;
		
		for (int val : score) {
			if (val>avg) cnt++;
		}
		
		float ratio = cnt/N*100;
		System.out.printf("%.3f%%\n",ratio);
		}
	}
}