Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <iomanip>
- #define ult s[s.length() - 1]-'a'
- #define prm s[0]-'a'
- using namespace std;
- ifstream fin("text.in");
- ofstream fout("text.out");
- vector < string > cuvinte;
- int p[20001], l[30], pos[30], C = 0;
- void Afisare(int pos)
- {
- if(pos == 0)
- return;
- C++;
- Afisare(p[pos]);
- fout << cuvinte[pos] << '\n';
- }
- int max(int a, int b, int &pos, int i)
- {
- if(a > b)
- return a;
- else
- {
- pos = i;
- return b;
- }
- }
- int main()
- {
- int c = 0;
- string s;
- cuvinte.push_back("");
- while(fin >> s)
- {
- c++;
- if(l[ult] < l[prm] + 1)
- {
- l[ult] = l[prm] + 1;
- pos[ult] = c;
- p[c] = pos[prm];
- }
- cuvinte.push_back(s);
- }
- fout << " \n";
- int maxim = 0, start = 0;
- for(int i = 0; i <= 30; i++)
- maxim = max(maxim, l[i], start, pos[i]);
- Afisare(start);
- fout.close();
- fout.open("text.out", ios::in | ios::out);
- fout << c << '\n' << c - C;
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement