평균은 넘겠지
2023. 1. 29. 00:47ㆍ개인공부/코딩테스트
cout << fixed; -> 소수점을 고정시켜줍니다.
cout.precision(3); -> 소수점 3번째자리까지 표현해줍니다.
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
34
35
36
37
38
39
40
41
42
43
44
45
|
#include <iostream>
using namespace std;
int main()
{
int TestCase = 0;
int StudentNumber = 0;
float OverAverageStudent = 0.f;
float AverageScore = 0.f;
cout << fixed;
cout.precision(3);
cin >> TestCase;
for (int i = 0; i < TestCase; ++i)
{
cin >> StudentNumber;
int* Score = new int[StudentNumber];
for (int j = 0; j < StudentNumber; ++j)
{
cin >> Score[j];
AverageScore += (float)Score[j];
}
AverageScore = AverageScore / (float)StudentNumber;
for (int j = 0; j < StudentNumber; ++j)
{
if (Score[j] > AverageScore)
{
++OverAverageStudent;
}
}
cout << OverAverageStudent / StudentNumber * 100 << "%" << endl;
OverAverageStudent = 0;
AverageScore = 0;
delete[] Score;
}
}
|
cs |