CS/알고리즘
[백준/JAVA] 1546번 : 평균
코딩 펭귄
2021. 9. 7. 12:37
https://www.acmicpc.net/problem/1546
1546번: 평균
첫째 줄에 시험 본 과목의 개수 N이 주어진다. 이 값은 1000보다 작거나 같다. 둘째 줄에 세준이의 현재 성적이 주어진다. 이 값은 100보다 작거나 같은 음이 아닌 정수이고, 적어도 하나의 값은 0보
www.acmicpc.net

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int[] score = new int[num];
int max = 0;
for(int i = 0; i < score.length; i++) {
score[i] = sc.nextInt();
if(score[i] > max) {
max = score[i];
}
}
double[] editScore = new double[num];
double sum = 0;
for(int i = 0; i < editScore.length; i++) {
editScore[i] = (double)score[i] / max * 100;
sum += editScore[i];
}
System.out.println(sum / num);
}
}