Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <utility>
  4.  
  5. using namespace std;
  6.  
  7. struct cmp
  8. {
  9. bool operator() (const pair<int,int>&a, const pair<int,int>&b)
  10. {
  11. if (a.first == b.first)
  12. return a.second<b.second;
  13. else
  14. return a.first > b.first;
  15. }
  16. };
  17. int main (void)
  18. {
  19. int i=0,n,foo;
  20. cin>>n;
  21. unordered_map <int, pair<int,int>, cmp > mymap;
  22. while (i != n)
  23. {
  24. //auto it = mymap.begin();
  25. cin>>foo;
  26. if (mymap.find(foo) == mymap.end())
  27. {
  28. mymap[foo].make_pair(1,i);
  29. }
  30. else
  31. {
  32. mymap[foo].first++;
  33. }
  34. i++;
  35. }
  36. auto it = mymap.begin();
  37. while (it != mymap.end())
  38. {
  39. cout<<it->first<<"t"<<it->second.first<<"t"<<it->second.second;
  40. cout<<"n";
  41. }
  42. return 0;
  43.  
  44. }
  45.  
  46. For ex: I/P: 2 5 2 8 5 6 8 8
  47. O/P: 8 8 8 2 2 5 5 6
  48.  
  49. no matching function for call to object of type 'const cmp'
  50. {return static_cast<const _Hash&>(*this)(__x);}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement