-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabove_average.cpp
41 lines (34 loc) · 1.08 KB
/
above_average.cpp
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
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main() {
int cases;
cin >> cases;
vector<float> answers;
for(int test = 0; test < cases; test++) {
vector<int> grades;
int students = 0, above_avg = 0, avg = 0;
cin >> students;
for(int stdnt = 0; stdnt < students; stdnt++) {
int grade;
cin >> grade;
avg += grade;
grades.push_back(grade);
}
avg = avg/students; /////may need to be changed
for(int index = 0; index < grades.size(); index++) {
if(grades[index] > avg) {
above_avg++;
}
}
float buff = 100.000000001;
float ans = (float) above_avg / (float) students;
ans *= (float) buff;
answers.push_back(ans);
//cout << fixed << setprecision(3) << ans << "%" << endl;
}
for(int index = 0; index < answers.size(); index++) {
cout << fixed << setprecision(3) << answers[index] << "%" << endl;
}
}