Advertisement
PedalaVasile

TEXT

Feb 14th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <iomanip>
  5. #define ult s[s.length() - 1]-'a'
  6. #define prm s[0]-'a'
  7. using namespace std;
  8. ifstream fin("text.in");
  9. ofstream fout("text.out");
  10. vector < string > cuvinte;
  11. int p[20001], l[30], pos[30], C = 0;
  12. void Afisare(int pos)
  13. {
  14.     if(pos == 0)
  15.         return;
  16.     C++;
  17.     Afisare(p[pos]);
  18.     fout << cuvinte[pos] << '\n';
  19. }
  20. int max(int a, int b, int &pos, int i)
  21. {
  22.     if(a > b)
  23.         return a;
  24.     else
  25.     {
  26.         pos = i;
  27.         return b;
  28.     }
  29. }
  30. int main()
  31. {
  32.     int c = 0;
  33.     string s;
  34.     cuvinte.push_back("");
  35.     while(fin >> s)
  36.     {
  37.         c++;
  38.         if(l[ult] < l[prm] + 1)
  39.         {
  40.             l[ult] = l[prm] + 1;
  41.             pos[ult] = c;
  42.             p[c] = pos[prm];
  43.         }
  44.         cuvinte.push_back(s);
  45.     }
  46.     fout << "                                                  \n";
  47.     int maxim = 0, start = 0;
  48.     for(int i = 0; i <= 30; i++)
  49.         maxim = max(maxim, l[i], start, pos[i]);
  50.     Afisare(start);
  51.     fout.close();
  52.     fout.open("text.out", ios::in | ios::out);
  53.     fout << c << '\n' << c - C;
  54.     fin.close();
  55.     fout.close();
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement