Click
Here to go back to the homepage.
Above Average Solution:
#include <bits/stdc++.h>
using namespace std;
int main(){
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int cases;
cin >> cases;
for (int i = 0; i < cases; ++i)
{
int n_scores;
cin >> n_scores;
int scores[n_scores];
int sum = 0;
for (int i = 0; i < n_scores; ++i)
{
cin >> scores[i];
sum += scores[i];
}
double average = (double) sum / n_scores;
int above_avg = 0;
for (int i = 0; i < n_scores; ++i)
{
if(scores[i] > average){
above_avg++;
}
}
cout << fixed << setprecision(3) << (double) above_avg / n_scores * 100 << "%" << endl;
}
return 0;
}