본문 바로가기
알고리즘/코딩테스트

[백준] 4344번 (자바풀이)

by dokii 2021. 11. 19.
728x90
반응형

 

import java.util.*;
public class jun4344_3 {

	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];
			
			float total=0;
			float sum=0;
			float avg=0;
			int count=0;
			for(int j=0; j<N; j++) {
				arr[j]=sc.nextInt();
				
				sum+= arr[j];
			}
			avg = sum/N;
			
			//구한 평균보다 높은 학생을 카운트하기
			for(int k=0; k<N; k++) {
				if(arr[k]>avg) {
					count++;
				}
			}
			
			total=(float)count/N;
			System.out.printf("%.3f%%\n", total*100);
		}//for end
		
		

	}

}

 

 

 

 

 

문제

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

 

4344번: 평균은 넘겠지

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

www.acmicpc.net

 

728x90
반응형

댓글