Algorithm

[백준] 1546번 평균 구하기

orieasy1 2024. 5. 6. 03:23

알고리즘 판다 1주차 문제

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

 

배열과 리스트 파트 문제

 

 

 

풀이는 다음과 같다.

코드를 더 간결하게 작성하기 위해 점수를 입력 받으면서 최고을 계산하도록 했다.

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        int[] score = new int[N];

        int M = 0;
        for(int i = 0; i < N; i++) {
            score[i] = scanner.nextInt();
            if(score[i] > M){
                M = score[i];
            }
        }

        double sum = 0.0;
        for(double i : score){
            sum += i / M * 100;
        }
        System.out.println(sum/N);
    }
}