본문 바로가기

[BOJ] - JAVA

[백준] 4344 : 평균은 넘겠지 JAVA 풀이

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.List;

public class Main{
    public static void main(String[] main)throws IOException{
        
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int C = Integer.parseInt(br.readLine());
        int[] arr;
        StringTokenizer st;

        for(int i=0;i<C;i++){
            st = new StringTokenizer(br.readLine(), " ");
            
            int N = Integer.parseInt(st.nextToken());
            arr = new int[N];
            
            double sum = 0;
            
            for(int j=0;j<N;j++){
                arr[j] = Integer.parseInt(st.nextToken());
                sum += arr[j];
            }
            double mean = sum/N;
            double count = 0;
            
            for(int val : arr){
                if(val>mean){
                    count++;
                }
            }
            
            System.out.printf("%.3f%%\n", count/N*100);
        }
    }
}

문제를 너무 어렵게 생각하는 것 같다~~~~