언어공부/[BAEKJOON] C#

[ BackJoon C# ] 1546 : 평균

zzerou 2023. 1. 8. 17:26

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

 

1546번: 평균

첫째 줄에 시험 본 과목의 개수 N이 주어진다. 이 값은 1000보다 작거나 같다. 둘째 줄에 세준이의 현재 성적이 주어진다. 이 값은 100보다 작거나 같은 음이 아닌 정수이고, 적어도 하나의 값은 0보

www.acmicpc.net

using System;
using System.Collections.Generic;
using System.Linq;

namespace BackJoonStudy
{
    class Program
    {
        static void Main(string[] args)
        {

            int value = int.Parse(Console.ReadLine());  // 과목 갯수

            string[] s = Console.ReadLine().Split();    // 과목 갯수에 따른 점수들
            float[] score = Array.ConvertAll(s, float.Parse);

            float max = float.MinValue;

            //최고점 알아내기
            for(int i = 0; i<value; i++)
            {
                if (score[i]>max)
                {
                    max = score[i];
                }
            }

            //값 더하기
            float sum = 0.0f;

            //점수계산
            for (int i=0; i<value; i++)
            {
                score[i] = score[i] / max * 100;
                sum += score[i];
            }

            //나타내기
            Console.WriteLine("{0:0.0###}",sum/value); 

        }
    }
}