fork download
  1.  
  2. typedef int score_t;
  3. typedef int count_t;
  4. #include <map>
  5. #include <iostream>
  6. #include <vector>
  7. int main()
  8. {
  9. std::map<score_t, count_t> data;
  10.  
  11. // step1: input: use ctrl-z to end
  12. for (score_t tmp; std::cin >> tmp;)
  13. {
  14. ++data[tmp];
  15. }
  16. // step2: get identical number
  17. std::vector<score_t> most_appeared;
  18. count_t max;
  19. std::map<score_t, count_t>::iterator i = data.begin();
  20. most_appeared.push_back(i->first);
  21. max = i->second;
  22. for (++i;
  23. i != data.end(); ++i)
  24. {
  25. if (i->second > max)
  26. {
  27. max = i->second;
  28. most_appeared.clear();
  29. most_appeared.push_back(i->first);
  30. }
  31. else if (i->second == max)
  32. {
  33. most_appeared.push_back(i->first);
  34. }
  35. else continue;
  36. }
  37. // step 3: output
  38. std::cout << "The highest score is: " << data.rbegin()->first << std::endl;
  39. std::cout << "The lowest score is: " << data.begin()->first << std::endl;
  40. std::cout << "The identical score"
  41. << (most_appeared.size() > 1 ? "s are: " : " is");
  42. for (int i = 0; i != most_appeared.size(); ++i)
  43. {
  44. std::cout << most_appeared[i] << " ";
  45. }
  46.  
  47. return 0;
  48. }
  49. /*
  50. see <c++ primer> 4th
  51. section 10.3.4#Programming Implications of the Subscript Behavior
  52. */
Success #stdin #stdout 0s 3476KB
stdin
3 1 4 1 5 9 2 5
stdout
The highest score is: 9
The lowest score is: 1
The identical scores are: 1 5