문제 풀이/백준

[백준] 1546번. 평균 (JAVA)

27200 2024. 1. 28. 02:33

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


문제


풀이

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(br.readLine());
        StringTokenizer sc = new StringTokenizer(br.readLine());

        int[] score = new int[N];
        int sum = 0;

        for(int i = 0; i < N; i++){
            score[i] = Integer.parseInt(sc.nextToken());
            sum += score[i];
        }

        Arrays.sort(score);
        System.out.println(sum * 100.0 / score[N-1] / N);

    }
}

 

문제의 풀이를 손으로 먼저 해결해 본다면 계산식을 조금 더 단순하게 구하기 쉽다고 생각한다.

분배법칙을 역으로 이용해 공통인수를 묶을 수 있어 해결이 쉬웠다.