티스토리 뷰

PS/boj

boj)4344

kingsubin 2020. 8. 29. 20:55
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int N = Integer.parseInt(br.readLine());

        for (int i = 0; i < N; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            int students = Integer.parseInt(st.nextToken()); // 학생 수
            double goodStudents = 0;
            double sum = 0;

            // 배열 저장
            int[] points = new int[students];
            for (int j = 0; j < students; j++) {
                points[j] = Integer.parseInt(st.nextToken());
                sum += points[j];
            }

            // avg
            double avg = sum / students;

            // goodStudents
            for (int point : points) {
                if (point > avg) {
                    goodStudents++;
                }
            }

            String ans = String.format("%.3f", (goodStudents/students * 100));
            bw.append(ans).append("%\n");
        }

        bw.flush();
        bw.close();
    }
}

 

- 막 깔끔하진 않은데 내가 생각했던대로 적어봤음


https://www.acmicpc.net/problem/4344

'PS > boj' 카테고리의 다른 글

boj)1911 - 흙길 보수하기  (0) 2020.08.31
boj)8958  (0) 2020.08.29
boj)10996  (0) 2020.08.29
boj)2446  (0) 2020.08.29
boj)2523  (0) 2020.08.29