AlenAntonelli

Letras_extremas_Alen

May 12th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. ///Trello, Principiante, Letras Extremas
  2. #include <iostream> /// AlenAntonelli
  3. #include <vector>
  4. using namespace std;
  5. int main ()
  6. {
  7.     int N=0, cmax=0, ban; /// N: cantidad de palabras. cmax: veces que se usa la/s extrerna mas usada
  8.     char tl[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};///vector con 26 contadores
  9.     vector <char> le, mle;///vectores que almacenen todas las letras externas y las mas usadas
  10.     vector <int> tc (26, 0);///vector con 26 letras
  11.     vector <string> v; /// vector de palabras
  12.     string aux; /// string auxiliar utililizada en los ingresos de cada palabra al...
  13.     cin >> N;
  14.     for (int i=0; i<N; i++)
  15.     {
  16.         cin >> aux;
  17.         v.push_back ( aux );
  18.     }
  19.     for (int i=0; i<N; i++)
  20.     {
  21.         le.push_back(v[i][0]);
  22.         le.push_back(v[i][  v[i].size()-1  ]);
  23.     }
  24.     for (int i=0; i<le.size(); i++)
  25.     {
  26.         ban=1;
  27.         for (int c=0; ban==1; c++)
  28.             if(tl[c]==le[i])
  29.             {
  30.                 tc[c]++;
  31.                 ban=0;
  32.             }
  33.     }
  34.     for (int c=0; c<26; c++)
  35.         if ((tc[c] != 0) && (tc[c] > cmax))
  36.             cmax = tc[c];
  37.     for (int c=0; c<26; c++)
  38.         if (tc[c]==cmax)
  39.             mle.push_back(tl[c]);
  40.     for (int i=0; i<mle.size(); i++)
  41.     {
  42.         cout <<mle[i]<<" ";
  43.         if (i != mle.size()-1)
  44.             cout<<" ";
  45.     }
  46.     for (int i=0; i<N; i++)
  47.     {
  48.         ban=1;
  49.         for (int j=0; j<mle.size() && ban==1; j++)
  50.             if (   ( v[i][0] == mle[j] )  ||  ( v[i][v[i].size()-1] == mle[j] )  )
  51.             {
  52.                 cout << endl << v[i];
  53.                 ban=0;
  54.             }
  55.     }
  56.     return N;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment