fork(3) download
  1. #include <iostream>
  2. #include <map>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. map<int,int> m;
  9. multimap<int,int,greater<int>> mm;
  10.  
  11. for(int i = 0; i < 40; ++i)
  12. {
  13. int v = rand()%20;
  14. m[v]++;
  15. cout << v << " ";
  16. }
  17. cout << endl;
  18.  
  19. for(auto v : m)
  20. mm.insert(make_pair(v.second,v.first));
  21.  
  22. for(auto v : mm)
  23. for(int i = 0; i < v.first; ++i)
  24. cout << v.second << " ";
  25. cout << endl;
  26.  
  27. }
  28.  
Success #stdin #stdout 0s 4292KB
stdin
Standard input is empty
stdout
3 6 17 15 13 15 6 12 9 1 2 7 10 19 3 6 0 6 12 16 11 8 7 9 2 10 2 3 7 15 9 2 2 18 9 7 13 16 11 2 
2 2 2 2 2 2 6 6 6 6 7 7 7 7 9 9 9 9 3 3 3 15 15 15 10 10 11 11 12 12 13 13 16 16 0 1 8 17 18 19