Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- vector <string> palabras(n);
- for(int i=0; i<n; i++)
- cin >> palabras[i];
- vector <set<string> > palabrasPorLetra(30);
- vector <int> cantPorLetra(30, 0);
- int maxRep = 0;
- for(int i=0; i<n; i++)
- {
- char a = palabras[i][0];
- char b = palabras[i].back();
- palabrasPorLetra[a-'a'].insert(palabras[i]);
- if(palabras[i].size() > 1)
- {
- palabrasPorLetra[b-'a'].insert(palabras[i]);
- cantPorLetra[b-'a']++;
- }
- maxRep = max(maxRep, cantPorLetra[a-'a']);
- maxRep = max(maxRep, cantPorLetra[b-'a']);
- }
- vector <char> letrasRta;
- vector <string> palabrasRta;
- for(int i=0; i<30; i++)
- {
- if(cantPorLetra[i] == maxRep)
- {
- letrasRta.push_back(i+'a');
- for(string pal:palabrasPorLetra[i])
- palabrasRta.push_back(pal);
- }
- }
- for(int i=0; i<letrasRta.size(); i++)
- cout << letrasRta[i] << " ";
- cout << endl;
- for(int i=0; i<palabrasRta.size(); i++)
- cout << palabrasRta[i] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment