백준 4344

Hyerin·2022년 1월 28일
0
post-thumbnail

문제

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

C# 풀이

using System;
using System.IO;

namespace baekjoon
{
    class Program
    {
        static void Main(string[] args)
        {
            // 표준 입출력 스트림 reader,writer 만들기
            // 첫째 줄에 테스트 케이스의 개수 C 입력받기, int로 바꾸기
            // 둘째 줄부터 각 테스트 케이스마다 학생의 수 N이 첫 수로 주어지고,
            // 이어서 N명의 점수까지 입력받기, 분리하기, int로 바꾸기
            // 각 케이스마다 한 줄씩 평균을 넘는 학생들의 비율을 반올림하여 소수점 셋째 자리까지 구하기
            // 버퍼에 저장
            // 버퍼 한 번에 비우기

            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());

            string strTestCase = sr.ReadLine();
            int nTestCase = int.Parse(strTestCase);

            for (int i = 0; i < nTestCase; i++) // 5
            {
                string strNum = sr.ReadLine(); // "5 50 50 70 80 100"
                string[] strArr = strNum.Split(' '); // ['5', '50', '50', '70', '60', 50']
                int nStudentNum = int.Parse(strArr[0]); // 5

                int nSum = 0;

                for (int j = 1; j <= nStudentNum; j++)
                {
                    int nScore = int.Parse(strArr[j]); // 50, 50, 70, 80, 100
                    nSum += nScore;
                }

                int nAverage = nSum / nStudentNum; // 70

                int nCount = 0;

                for (int j = 1; j <= nStudentNum; j++)
                {
                    int nScore = int.Parse(strArr[j]); // 50, 50, 70, 80, 100

                    if (nAverage < nScore)
                    {
                        nCount++;
                    }
                    else
                    {
                        continue;
                    }
                }

                double nResult = Math.Round(((double)nCount / nStudentNum), 5) * 100; // 40
                sw.WriteLine(string.Format("{0:0.000}%", nResult));
            }

            sw.Flush();
            sr.Close();
            sw.Close();
        }
    }
}

0개의 댓글