[JAVA] 백준 알고리즘 4344 : 평균은 넘겠지
평균이 넘는 학생들의 퍼센테이지를 출력하는 문제
문제
소스 |
import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int cntRow = sc.nextInt(); // 시험 수 int cnt, sum, over; double result, per; for (int i=0; i<cntRow; i++) { cnt = sc.nextInt(); sum = 0; over = 0; result = 0.0; int score[] = new int[cnt]; // 배열에 점수 입력 및 총 합계 for (int j=0; j<cnt; j++) { score[j] = sc.nextInt(); sum += score[j]; } // 평균을 넘는 학생 수 for (int j=0; j<cnt; j++) { if (score[j] > (double)sum/cnt) { over++; } } // 비율 result = (double)over/cnt*100; // 소수점 셋째짜리까지 표현 (10의 N(자리수)제곱으로 곱한 후 다시 N제곱으로 나눔) per = Math.round(result*1000)/1000.0; // 결과 출력 System.out.printf("%.3f", per); System.out.println("%"); } } }
출처 |
https://www.acmicpc.net/problem/4344