Advertisement
a53

text

a53
Feb 28th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cstring>
  4. #include <vector>
  5. #define x first
  6. #define y second
  7. #define NMAX 20007
  8. using namespace std;
  9.  
  10. pair< int, int > Ap[37];
  11. vector< int > SOL;
  12. char a[NMAX][NMAX / 1000];
  13. int Sol[NMAX];
  14.  
  15. int main()
  16. {
  17. freopen("text.in", "r", stdin);
  18. freopen("text.out", "w", stdout);
  19. int n = 1;
  20. while(scanf(" %s ", a[n]) == 1){
  21. int Lung = strlen(a[n]) - 1;
  22. if(Ap[a[n][Lung] - 'a'].x < Ap[a[n][0] - 'a'].x + 1){
  23. Ap[a[n][Lung] - 'a'].x = Ap[a[n][0] - 'a'].x + 1;
  24. Sol[n] = Ap[a[n][0] - 'a'].y;
  25. Ap[a[n][Lung] - 'a'].y = n;
  26. }
  27. ++n;
  28. }
  29. printf("%d\n", n - 1);
  30. int Max = 0, Nr = 0;
  31. for(int i = 0; i <= 26; ++i)
  32. if(Max < Ap[i].x){
  33. Max = Ap[i].x;
  34. Nr = Ap[i].y;
  35. }
  36. printf("%d\n", n - Max - 1);
  37. while(Nr > 0){
  38. ///printf("%s\n", a[Nr]);
  39. SOL.push_back(Nr);
  40. Nr = Sol[Nr];
  41. }
  42. for(int i = SOL.size() - 1; i >= 0; -- i)
  43. printf("%s\n", a[SOL[i]]);
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement