GastonFontenla

Untitled

Jul 1st, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int n;
  10.     cin >> n;
  11.     vector <string> palabras(n);
  12.  
  13.     for(int i=0; i<n; i++)
  14.         cin >> palabras[i];
  15.  
  16.     vector <set<string> > palabrasPorLetra(30);
  17.     vector <int> cantPorLetra(30, 0);
  18.  
  19.     int maxRep = 0;
  20.  
  21.     for(int i=0; i<n; i++)
  22.     {
  23.         char a = palabras[i][0];
  24.         char b = palabras[i].back();
  25.  
  26.         palabrasPorLetra[a-'a'].insert(palabras[i]);
  27.  
  28.         if(palabras[i].size() > 1)
  29.         {
  30.             palabrasPorLetra[b-'a'].insert(palabras[i]);
  31.             cantPorLetra[b-'a']++;
  32.         }
  33.  
  34.         maxRep = max(maxRep, cantPorLetra[a-'a']);
  35.         maxRep = max(maxRep, cantPorLetra[b-'a']);
  36.     }
  37.  
  38.     vector <char> letrasRta;
  39.     vector <string> palabrasRta;
  40.  
  41.     for(int i=0; i<30; i++)
  42.     {
  43.         if(cantPorLetra[i] == maxRep)
  44.         {
  45.             letrasRta.push_back(i+'a');
  46.             for(string pal:palabrasPorLetra[i])
  47.                 palabrasRta.push_back(pal);
  48.         }
  49.     }
  50.  
  51.     for(int i=0; i<letrasRta.size(); i++)
  52.         cout << letrasRta[i] << " ";
  53.     cout << endl;
  54.  
  55.     for(int i=0; i<palabrasRta.size(); i++)
  56.         cout << palabrasRta[i] << endl;
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment