백준 4344
문제
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();
}
}
}
Author And Source
이 문제에 관하여(백준 4344), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://velog.io/@helenhihi/백준
저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
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();
}
}
}
Author And Source
이 문제에 관하여(백준 4344), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@helenhihi/백준저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)