백준 1546번 (복습)

김경욱·2026년 1월 25일

백준

목록 보기
117/121

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

// Press Shift twice to open the Search Everywhere dialog and type show whitespaces,
// then press Enter. You can now see whitespace characters in your code.
public class Main {
public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

    StringTokenizer st = new StringTokenizer(br.readLine());

    int[] arr = new int[x];

    for (int i = 0; i < x; i++) {
        arr[i] = Integer.parseInt(st.nextToken());
    }

    int max = arr[0];

    for (int i = 0; i < x; i++) {
        if(max<=arr[i])
        {
            max = arr[i];
        }
    }


    double total = 0;

    for (int i = 0; i < x; i++) {
        total += arr[i];
    }





    System.out.println(  total * 100 / max /x);











}

}
이렇게 나눗셈이나 곱셉을 해야할 경우에는 최대한 마지막에 해서 오차값을 줄이는게 좋다. 미리 다 곱하고 나누면 오차값이 커짐!

0개의 댓글