AlenAntonelli

nombres_Alen

May 13th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. ///Trello, Facil, Descubriendo nombres repetidos
  2. #include <iostream> /// AlenAntonelli
  3. #include <vector>
  4. #include <map>
  5. using namespace std;
  6. int main ()
  7. {
  8.     int N, c=0;
  9.     vector <pair <int, string>> may (3, {0,""});
  10.     cin>>N; ///cin>>topFrecuentes;
  11.     vector <string> nombres (N);
  12.     cout<<"["<<N<<"]"<<endl;
  13.     map <string, int> mapa;
  14.     for (int i=0; i<N; i++)
  15.     {
  16.         cin>>nombres[i];
  17.         mapa[ nombres[i] ]++; ///magic line
  18.     }
  19.  
  20.     map <string, int>::iterator it= it=mapa.begin();
  21.     for ( ; it!=mapa.end(); it++)
  22.     {///cout<< (*it).first << " " << (*it).second << endl;
  23.         if ((*it).second > may[0].first)
  24.         {
  25.             may[2].first=may[1].first;
  26.             may[2].second=may[1].second;
  27.  
  28.             may[1].first=may[0].first;
  29.             may[1].second=may[0].second;
  30.  
  31.             may[0].first = (*it).second;
  32.             may[0].second = (*it).first;
  33.             continue;
  34.         }
  35.         if ((*it).second > may[1].first)
  36.         {
  37.             may[2].first=may[1].first;
  38.             may[2].second=may[1].second;
  39.  
  40.             may[1].first = (*it).second;
  41.             may[1].second = (*it).first;
  42.             continue;
  43.         }
  44.         if ((*it).second > may[2].first)
  45.         {
  46.             may[2].first = (*it).second;
  47.             may[2].second = (*it).first;
  48.             continue;
  49.         }
  50.     }
  51.  
  52.     for (int i=0; i<3; i++)
  53.         cout<<may[i].second<<" "<<may[i].first<<endl;
  54.  
  55.     return may[0].first;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment