Advertisement
Guest User

Untitled

a guest
Apr 5th, 2012
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <map>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <iostream>
  5. #include <string.h>
  6.  
  7. using namespace std;
  8.  
  9. int main ()
  10. {
  11.     int n;
  12.     cin>>n;
  13.     map<string, int> m;
  14.     map<string, int>::iterator it;
  15.     string s;
  16.  
  17.     for (int i=0; i!=n; ++i)
  18.         {
  19.             cin>>s;
  20.             m[s]++;
  21.         }
  22.  
  23.     multimap<int, string> mm;
  24.     multimap<int, string>::reverse_iterator mit;
  25.  
  26.     for (it=m.begin(); it!=m.end(); ++it)
  27.         mm.insert(make_pair(it->second, it->first));
  28.  
  29.     int step=0;
  30.     int prev=0;
  31.  
  32.     for (mit=mm.rbegin(); mit!=mm.rend(); ++mit)
  33.         {
  34.             if (step==3) break;
  35.             cout<<mit->first<<" "<<mit->second<<endl;
  36.             if (mit->first != prev) step++;
  37.             prev = mit->first;
  38.         }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement