본문 바로가기

Algorithm/백준 알고리즘

백준 알고리즘 4344 풀이 [자바, Java]

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

 

4344번: 평균은 넘겠지

문제 대학생 새내기들의 90%는 자신이 반에서 평균은 넘는다고 생각한다. 당신은 그들에게 슬픈 진실을 알려줘야 한다. 입력 첫째 줄에는 테스트 케이스의 개수 C가 주어진다. 둘째 줄부터 각 �

www.acmicpc.net

import java.util.Scanner;

public class Problem4344 {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int C = sc.nextInt();
		
		for(int i = 0; i < C; i++) {
			
			int N = sc.nextInt();
			int[] arr = new int[N];
			int sum = 0;
			int count = 0;
			
			for(int j = 0; j < N; j++) {
				arr[j] = sc.nextInt();
				sum += arr[j];
			}
			
			int avg = sum / arr.length;
			
			for(int j = 0; j < N; j++) {
				if(arr[j] > avg) {
					count++;
				}
			}
			System.out.printf("%.3f", (float) count / arr.length * 100);
			System.out.print("%");
			System.out.println();
		
		}
		

	}

}

풀이