AlenAntonelli

Letras_extremas_Map_Alen

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