알고리즘/백준 알고리즘
(JAVA) 백준 알고리즘 4344 문제 - 평균은 넘겠지
Love of fate
2020. 10. 6. 16:14
728x90
반응형
(20분)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
public class Main {
public static void main(String[] args) {
//평균은 넘겠지
Scanner sc = new Scanner(System.in);
int testCase = sc.nextInt();
float [] rate = new float [testCase];
sc.nextLine();
//sc.nestLine()은 엔터를 인식하기 때문에 처음에 ""이 들어간다 그래서 다음과 같이
//한번 sc.nextLine()을 써주고 다음 코드를 써내려가야 한다.
for(int i = 0; i < testCase; i++) {
String [] jumsu = null;
jumsu = sc.nextLine().split(" ");
float totAvg = 0;
for(int j = 1; j < jumsu.length; j++) {
totAvg += Float.parseFloat(jumsu[j]);
}
totAvg = totAvg/Integer.parseInt(jumsu[0]);
int su = 0;
for(int j = 1; j < jumsu.length; j++) {
int stuJumsu = Integer.parseInt(jumsu[j]);
if(stuJumsu > totAvg) {
su +=1;
}
}
rate[i] = su/Float.parseFloat(jumsu[0])*100;
}
for(int i =0; i < testCase; i++) {
System.out.println(String.format("%.3f", rate[i]) + "%");
}
}
}
|
728x90
반응형