fork(1) download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <iterator>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <numeric>
  7.  
  8. int main()
  9. {
  10. std::ifstream inp("scores.dat");
  11. std::vector<int> scores;
  12. std::copy(std::istream_iterator<int>(std::cin), std::istream_iterator<int>(),
  13. std::back_inserter(scores));
  14. auto minmax(std::minmax_element(std::begin(scores), std::end(scores)));
  15. int excellent(0), satisfactory(0), normal(0), needImprovement(0);
  16. double average = std::accumulate(std::begin(scores), std::end(scores), 0,
  17. [&](int x, int y)
  18. { if (y < 50) ++needImprovement;
  19. else if (y < 80) ++normal;
  20. else if (y < 95) ++satisfactory;
  21. else ++excellent;
  22. return x + y; });
  23. average /= scores.size();
  24. std::cout << "Maximum score is: " << *(minmax.second) << "\n" <<
  25. "Minimum score is: " << *(minmax.first) << "\n" <<
  26. "Average score is: " << average << "\n" <<
  27. "There is:\n" << excellent << " Excellent scores\n" <<
  28. satisfactory << " Satisfactory scores\n" << normal <<
  29. " Normal scores\n" << needImprovement << " Needs improvement!";
  30. }
Runtime error #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
Standard output is empty