fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <tuple>
  4. #include <list>
  5. #include <set>
  6. class Example
  7. {
  8. std::string one, two, three, four, five;
  9. public:
  10. Example(const std::string& a_one, const std::string& a_two,
  11. const std::string& a_three,
  12. const std::string& a_four, const std::string& a_five) :
  13. one(a_one),two(a_two),three(a_three),four(a_four),five(a_five)
  14. {}
  15. bool operator < (const Example& other) const
  16. {
  17. return std::tie(one, two, three, four, five)
  18. < std::tie(other.one, other.two, other.three, other.four,
  19. other.five);
  20. }
  21. friend std::ostream& operator<<(std::ostream& os, const Example& e) {
  22. return os << "[" << e.one << "," << e.two << "," << e.three << "," << e.four << "," << e.five << "]";
  23. }
  24. };
  25.  
  26.  
  27. std::list<Example> GetExamples()
  28. {
  29. std::list<Example> result;
  30. result.push_back(Example("duplicate", "a", "a", "a", "a"));
  31. result.push_back(Example("unique", "2", "4", "0", "0"));
  32. result.push_back(Example("duplicate", "a", "a", "a", "a"));
  33. result.push_back(Example("unique", "2", "3", "4", "5"));
  34. return result;
  35. }
  36. void CountExample(const Example& example, std::multiset<Example>& counters)
  37. {
  38. counters.insert(example);
  39. }
  40.  
  41. void PrintCounters(const std::multiset<Example>& counters)
  42. {
  43. for(auto i=counters.begin(); i!=counters.end(); i = counters.upper_bound(*i))
  44. std::cout << *i << ":" << counters.count(*i) << '\n';
  45. }
  46.  
  47. int main()
  48. {
  49. std::multiset<Example> counters;
  50. std::list<Example> examples = GetExamples();
  51. std::list<Example>::const_iterator Iter;
  52. for (Iter = examples.begin(); Iter != examples.end();Iter++)
  53. {
  54. CountExample(*Iter, counters);
  55. }
  56. PrintCounters(counters);
  57. }
  58.  
Success #stdin #stdout 0s 2976KB
stdin
Standard input is empty
stdout
[duplicate,a,a,a,a]:2
[unique,2,3,4,5]:1
[unique,2,4,0,0]:1