Baekjoon Algorithm | Problem 4344: Above Average
Source
https://www.acmicpc.net/problem/4344
Problem
Solve Baekjoon Online Judge problem 4344, Above Average.
Input
Follow the input format and constraints given in the original problem statement.
Output
Print the answer required by the problem.
Sample Input 1
5 5 50 50 70 80 100 7 100 95 90 80 70 60 50 3 70 90 80 3 70 90 81 9 100 99 98 97 96 95 94 93 91
Sample Output 1
40.000% 57.143% 33.333% 66.667% 55.556%
Algorithm Classification
- Math
- Arithmetic
Solution
import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
try (
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out))
) {
int c = Integer.parseInt(br.readLine());
for (int i = 0; i < c; i++) {
StringTokenizer input = new StringTokenizer(br.readLine(), " ");
int n = Integer.valueOf(input.nextToken());
int[] scores = new int[n];
int sum = 0;
for (int j = 0; j < n; j++) {
int score = Integer.valueOf(input.nextToken());
scores[j] = score;
sum += score;
}
float avg = (float) sum / (float) n;
int highCount = 0;
for (int j = 0; j < n; j++) {
if (avg < scores[j]) {
highCount++;
}
}
bw.write(String.format("%.3f%%\n", (((float) highCount / n) * 100)));
}
bw.flush();
}
}
}