Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- using namespace std;
- ifstream fin("text.in");
- ofstream fout("text.out");
- int v[30];
- vector<string> cuv;
- vector<int> cod[30];
- string s;
- int main()
- {
- int nrc = 0;
- while(fin>>s)
- {
- cuv.push_back(s);
- int first, last;
- last = s[s.size()-1] - 'a';
- first = s[0] - 'a';
- if(v[last] <= v[first])
- {
- v[last] = v[first] + 1;
- cod[last] = cod[first];
- cod[last].push_back(nrc);
- }
- nrc++;
- }
- int maxim=0, i, imax;
- for(i=0; i<30; i++)
- {
- if(v[i] >= maxim)
- {
- maxim = v[i];
- imax = i;
- }
- }
- fout<<nrc<<'\n'<<nrc-maxim<<'\n';
- for(i=0; i<cod[imax].size(); i++)
- {
- fout<<cuv[cod[imax][i]]<<'\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement