본문 바로가기
알고리즘/백준

[백준 1546번 ː 자바(JAVA)] 평균

by 그릿er 2020. 4. 27.

 

<문제>

 

세준이는 기말고사를 망쳤다. 세준이는 점수를 조작해서 집에 가져가기로 했다. 일단 세준이는 자기 점수 중에 최댓값을 골랐다. 이 값을 M이라고 한다. 그리고 나서 모든 점수를 점수/M*100으로 고쳤다.

예를 들어, 세준이의 최고점이 70이고, 수학점수가 50이었으면 수학점수는 50/70*100이 되어 71.43점이 된다.

세준이의 성적을 위의 방법대로 새로 계산했을 때, 새로운 평균을 구하는 프로그램을 작성하시오.

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
 
 
public class Main {
 
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        
        int subnum = sc.nextInt();
        float max;
        float tot=0;
        float[] score = new float[subnum];
        
        for(int i=0; i<subnum; i++) {
            score[i] = sc.nextInt();
        }
        max = score[0];
        for(int i=1; i<score.length; i++) {
            if(max<score[i]) max = score[i];
        }
        for(int i=0; i<score.length; i++) {
            score[i] = score[i]/max*100;
            tot += score[i];
        }
        tot = tot/subnum;
        System.out.println(tot);
        }
    }