Advertisement
PedalaVasile

Text-Dan

Feb 20th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. ifstream fin("text.in");
  7. ofstream fout("text.out");
  8.  
  9. int v[30];
  10.  
  11. vector<string> cuv;
  12. vector<int> cod[30];
  13.  
  14. string s;
  15.  
  16. int main()
  17. {
  18.     int nrc = 0;
  19.     while(fin>>s)
  20.     {
  21.         cuv.push_back(s);
  22.  
  23.         int first, last;
  24.         last = s[s.size()-1] - 'a';
  25.         first = s[0] - 'a';
  26.         if(v[last] <= v[first])
  27.         {
  28.             v[last] = v[first] + 1;
  29.             cod[last] = cod[first];
  30.             cod[last].push_back(nrc);
  31.         }
  32.         nrc++;
  33.     }
  34.  
  35.     int maxim=0, i, imax;
  36.     for(i=0; i<30; i++)
  37.     {
  38.         if(v[i] >= maxim)
  39.         {
  40.             maxim = v[i];
  41.             imax = i;
  42.         }
  43.     }
  44.  
  45.     fout<<nrc<<'\n'<<nrc-maxim<<'\n';
  46.  
  47.     for(i=0; i<cod[imax].size(); i++)
  48.     {
  49.         fout<<cuv[cod[imax][i]]<<'\n';
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement