fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. void displayFrequentNumber(const std::vector<int>& input)
  6. {
  7. std::vector<std::pair<int, std::size_t>> v;
  8.  
  9. for (std::size_t i = 0; i != input.size(); ++i) {
  10. v.push_back({input[i], i});
  11. }
  12. std::sort(begin(v), end(v));
  13. for (auto it = begin(v); it != end(v); ) {
  14. auto next = find_if(it, end(v),
  15. [it](const std::pair<int, std::size_t>& rhs)
  16. {return it->first != rhs.first;});
  17. if (next - it >= 3) {
  18. std::cout << it->first << ":";
  19. for (; it != next; ++it) {
  20. std::cout << " " << it->second;
  21. }
  22. std::cout << std::endl;
  23. }
  24. it = next;
  25. }
  26. }
  27.  
  28. int main(int argc, char *argv[])
  29. {
  30. displayFrequentNumber({6,4,4,5,2,4,4,3,5,5});
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
4: 1 2 5 6
5: 3 8 9