백준 4344 평균은넘겠지(Java)
by 개발자 우디문제보기
정답
package baekjoon.ex_array;
import java.util.Scanner;
public class Q_4344 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String str = br.readLine();
int C = Integer.parseInt(str);
List<String> arr = new ArrayList<String>(); // 모든 입력값
for (int i = 0; i < C; i++) {
// bw.append(i + "\n");
arr.add(br.readLine());
}
List<Integer> avgChk = new ArrayList<Integer>();
int sum;
int overChk;
double pers;
for (int i = 0; i < C; i++) {
int count = Integer.parseInt(arr.get(i).split(" ")[0]);
sum = 0;
overChk = 0;
pers = 0;
for (int j = 1; j < count + 1; j++) {
sum += Integer.parseInt(arr.get(i).split(" ")[j]);
}
int tmp = sum / count;
avgChk.add(tmp);
for (int k = 1; k < count + 1; k++) {
// 평균보다 높은 사람 찾기
if (avgChk.get(i) < Integer.parseInt(arr.get(i).split(" ")[k])) {
overChk++;
}
}
// pers = (overChk + 0.000) / count;
// pers = pers * 100;
// DecimalFormat df = new DecimalFormat("#.###");
// String resPers = df.format(pers);
// result.add(resPers);
System.out.printf("%.3f", 100.0 * overChk / count);
System.out.println("%");
}
br.close();
bw.flush();
bw.close();
}
}
블로그의 정보
우디의 개발스터디
개발자 우디