BOJ 4344 평균은 넘겠지

Jmnote (토론 | 기여)님의 2018년 7월 27일 (금) 03:36 판

1 개요

BOJ 4344 평균은 넘겠지

[[분류:BOJ {{{단계}}}단계]]

  • 평균이 넘는 학생들의 퍼센테이지를 출력하는 문제

2 Java

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for( int i=0; i<n; i++ ) {
            int m = sc.nextInt();
            int[] nums = new int[m];
            for( int j=0; j<m; j++ ) {
                nums[j] = sc.nextInt();
            }
            double avg = Arrays.stream(nums).average().getAsDouble();
            int cnt = 0;
            for( int j=0; j<m; j++ ) {
                if( nums[j]>avg ) cnt++;
            }
            System.out.format("%.3f%%\n", 100.0*cnt/m);
        }
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}