๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Coding Test/Algorithms

[Baekjoon] 1546. ํ‰๊ท /Java - Bronze1

by The Future Engineer, Lucy 2024. 9. 28.
728x90
๋ฐ˜์‘ํ˜•

โ“๋ฌธ์ œ

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

๐Ÿ“Œ์œ ํ˜•

์ˆ˜ํ•™, ์‚ฌ์น™์—ฐ์‚ฐ

โœ๐Ÿปํ’€์ด

A, B, C๋ผ๋Š” ์ ์ˆ˜๊ฐ€ ์žˆ๋‹ค๋ฉด
(A/M*100 + B/M*100 + C/M*100)/3์€ ๊ฒฐํ•ฉ๋ฒ•์น™์— ์˜ํ•ด (A+B+C)*100/M/3๊ณผ ๊ฐ™๋‹ค
๊ทธ๋Ÿฌ๋ฏ€๋กœ ๋จผ์ € ์ ์ˆ˜์˜ ํ•ฉ์„ ๊ตฌํ•˜๊ณ  ๊ทธ์™€ ๋™์‹œ์— ์ตœ๋Œ“๊ฐ’๋„ ๊ตฌํ•œ๋‹ค.

๐Ÿ’ป์ฝ”๋“œ

import java.util.*;

public class Main {

    static int n;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        float[] score = new float[n];

        for (int i = 0; i < n; i++) {
            score[i] = sc.nextInt();
        }

        float m = 0;
        float sum = 0;
        for (int i = 0; i < n; i++) {
            if (score[i] > m) {
                m = score[i];
            }
            sum += score[i];
        }
        
        System.out.println(sum * 100.0/ m / n);
    }
}

 

728x90
๋ฐ˜์‘ํ˜•