본문 바로가기
코딩 테스트/백준

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

by snow_hong 2023. 5. 2.

-백준 문제 링크

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

 

4344번: 평균은 넘겠지

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

www.acmicpc.net


[ 문제 ]


[ 풀이 ] 

import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		
		Main mn = new Main();
		mn.test11();
		
	}
    
    private void test11() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int num = Integer.parseInt(br.readLine());
		
		for(int i=0; i<num; i++){
			
			StringTokenizer st = new StringTokenizer(br.readLine(), " ");
			int study = Integer.parseInt(st.nextToken());
			
			int[] arr = new int[study];
			
			for(int j=0; j<study; j++){
				arr[j] = Integer.parseInt(st.nextToken());
			}
			double avg = Arrays.stream(arr).average().getAsDouble();
			
			int cnt = 0;
			
			for(int k=0;k<study; k++){
				if(arr[k] > avg ){
					cnt++;
				}
			}
			
			double result = (float)cnt/study * 100;
			
			System.out.printf("%.3f%% \n",result);
			
		}
		
	}
}
728x90

댓글