fork download
  1. #include <cstdio>
  2. using namespace std;
  3.  
  4. double solve(int N, int scores[]) {
  5. int sum = 0;
  6. for (int i = 0; i < N; ++i) {
  7. sum += scores[i];
  8. }
  9. double avg = (double)sum / N;
  10.  
  11. int students = 0;
  12. for (int i = 0; i < N; ++i) {
  13. if (avg < scores[i]) students++;
  14. }
  15. return 100. * students / N;
  16. }
  17.  
  18. int main() {
  19. int C, N;
  20. int scores[1000] = {0};
  21.  
  22. scanf("%d", &C);
  23. for (int i = 0; i < C; ++i) {
  24. scanf("%d", &N);
  25. for (int j = 0; j < N; ++j) {
  26. scanf("%d", &scores[j]);
  27. }
  28. printf("%.3f%%\n", solve(N, scores));
  29. }
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 15232KB
stdin
5
5 50 50 70 80 100
7 100 95 90 80 70 60 50
3 70 90 80
3 70 90 81
9 100 99 98 97 96 95 94 93 91
stdout
40.000%
57.143%
33.333%
66.667%
55.556%