-백준 문제 링크
https://www.acmicpc.net/problem/4344
4344번: 평균은 넘겠지
대학생 새내기들의 90%는 자신이 반에서 평균은 넘는다고 생각한다. 당신은 그들에게 슬픈 진실을 알려줘야 한다.
www.acmicpc.net
[ 문제 ]
[ 풀이 ]
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Main mn = new Main();
mn.test11();
}
private void test11() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num = Integer.parseInt(br.readLine());
for(int i=0; i<num; i++){
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
int study = Integer.parseInt(st.nextToken());
int[] arr = new int[study];
for(int j=0; j<study; j++){
arr[j] = Integer.parseInt(st.nextToken());
}
double avg = Arrays.stream(arr).average().getAsDouble();
int cnt = 0;
for(int k=0;k<study; k++){
if(arr[k] > avg ){
cnt++;
}
}
double result = (float)cnt/study * 100;
System.out.printf("%.3f%% \n",result);
}
}
}
728x90
'코딩 테스트 > 백준' 카테고리의 다른 글
[백준 10798번] java 세로읽기 (0) | 2023.04.20 |
---|---|
[ 백준 2675번 ] java 문자열 반복 (0) | 2023.04.14 |
[백준] 1152번 단어의 개수 - java 성능별 4개의 정답 (0) | 2023.04.13 |
댓글