Nerde Nolzda

UVa10370: Above Average

簡單地算出平均並迴圈計算大於平均的人數。
Simply calculate the average and loop to count the number of people having a score higher than that.

UVa Link

#include <iostream>
#include <iomanip>

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);
  std::cout << std::fixed << std::setprecision(3);
  int c;
  std::cin >> c;
  while (c--) {
    int n, arr[1000], count = 0;
    float avg = 0;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
      std::cin >> arr[i];
      avg += arr[i];
    }
    avg /= n;
    for (int i = 0; i < n; i++) {
      if (arr[i] > avg) count++;
    }
    std::cout << (float)count / n * 100 << "%\n";
  }
}

Related Posts

0 comments

Post a comment

Send an email to comment@nerde.pw.