[BOJ] 4344번 평균은 넘겠지

나르·2021년 1월 7일
0

알고리즘

목록 보기
6/15

백준#4344 평균은 넘겠지
https://www.acmicpc.net/problem/4344

코드 - Python

for i in range(int(input())):
    a = list(map(int, input().split()))
    avg = sum(a[1:])/a[0]
    cnt = 0
    for j in a[1:]:
        if j > avg:
            cnt += 1
    print(str("%.3f" % round((cnt/a[0])*100, 3)) + "%")

코드 - Java

import java.io.*;
public class Main {
    public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		for(int i=0;i<n;i++){
	        String[] new_a = br.readLine().split(" ");
			int[] num = new int[new_a.length];
			for(int j=0;j<new_a.length;j++) {
				num[j] = Integer.parseInt(new_a[j]);
			}
			int sum = 0;
			for(int j=1;j<num.length;j++) {
				sum+=num[j];
			}
			double avg = sum/(double)num[0];
			double cnt = 0;
			for(int j=1;j<num.length;j++) {
				if(num[j]>avg) {
					cnt++;
				}
			}
			System.out.printf("%.3f%%\n",(cnt/num[0])*100);
		}
    }
}
profile
💻 + ☕ = </>

0개의 댓글