fork download
  1. #include <vector>
  2. #include <map>
  3. #include <iostream>
  4.  
  5. int main(int argc, char ** argv)
  6. {
  7. const std::vector<int> scores = {76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189,
  8. 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87,
  9. 35, 157, 189
  10. };
  11. std::map<int, int> scoreCount;
  12. std::cout << "Number of Scores: " << scores.size() << "\n";
  13.  
  14. for(auto score : scores)
  15. {
  16. scoreCount[score/25] ++;
  17. std::cout << score << " - scoreCount Index: " << score/25 << "\n";
  18. }
  19.  
  20. for(auto const& slot : scoreCount)
  21. {
  22. auto low = slot.first*25;
  23. auto high = low+24;
  24. std::cout << "Range " << low << "-" << high << ": " << slot.second << "\n";
  25. }
  26.  
  27. int sum = 0;
  28. for(auto const& slot : scoreCount)
  29. sum += slot.second;
  30.  
  31. if(sum < 26)
  32. printf("\n%d: Wrong number of scores counted.\n", sum);
  33. else
  34. printf("\nAll students accounted for.\n");
  35. }
  36.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
Number of Scores: 26
76 - scoreCount Index: 3
89 - scoreCount Index: 3
150 - scoreCount Index: 6
135 - scoreCount Index: 5
200 - scoreCount Index: 8
76 - scoreCount Index: 3
12 - scoreCount Index: 0
100 - scoreCount Index: 4
150 - scoreCount Index: 6
28 - scoreCount Index: 1
178 - scoreCount Index: 7
189 - scoreCount Index: 7
167 - scoreCount Index: 6
200 - scoreCount Index: 8
175 - scoreCount Index: 7
150 - scoreCount Index: 6
87 - scoreCount Index: 3
99 - scoreCount Index: 3
129 - scoreCount Index: 5
149 - scoreCount Index: 5
176 - scoreCount Index: 7
200 - scoreCount Index: 8
87 - scoreCount Index: 3
35 - scoreCount Index: 1
157 - scoreCount Index: 6
189 - scoreCount Index: 7
Range 0-24: 1
Range 25-49: 2
Range 75-99: 6
Range 100-124: 1
Range 125-149: 3
Range 150-174: 5
Range 175-199: 5
Range 200-224: 3

All students accounted for.