Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <vector>
- #define x first
- #define y second
- #define NMAX 20007
- using namespace std;
- pair< int, int > Ap[37];
- vector< int > SOL;
- char a[NMAX][NMAX / 1000];
- int Sol[NMAX];
- int main()
- {
- freopen("text.in", "r", stdin);
- freopen("text.out", "w", stdout);
- int n = 1;
- while(scanf(" %s ", a[n]) == 1){
- int Lung = strlen(a[n]) - 1;
- if(Ap[a[n][Lung] - 'a'].x < Ap[a[n][0] - 'a'].x + 1){
- Ap[a[n][Lung] - 'a'].x = Ap[a[n][0] - 'a'].x + 1;
- Sol[n] = Ap[a[n][0] - 'a'].y;
- Ap[a[n][Lung] - 'a'].y = n;
- }
- ++n;
- }
- printf("%d\n", n - 1);
- int Max = 0, Nr = 0;
- for(int i = 0; i <= 26; ++i)
- if(Max < Ap[i].x){
- Max = Ap[i].x;
- Nr = Ap[i].y;
- }
- printf("%d\n", n - Max - 1);
- while(Nr > 0){
- ///printf("%s\n", a[Nr]);
- SOL.push_back(Nr);
- Nr = Sol[Nr];
- }
- for(int i = SOL.size() - 1; i >= 0; -- i)
- printf("%s\n", a[SOL[i]]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement