Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <bits/stdc++.h>
  4. #include <map>
  5. #define pb push_back
  6. #define ll long long
  7. #define pii pair<int,int>
  8. #define pll pair<long,long>
  9. using namespace std;
  10.  
  11. int rez;
  12. vector<string> ans;
  13. vector<string> v;
  14. int dp[28];
  15. int i,j,k,index=0,firstcount=0;
  16. vector<vector<string> > mat;
  17.  
  18. template <typename Out>
  19. void split(const std::string &s, char delim, Out result) {
  20. std::istringstream iss(s);
  21. std::string item;
  22. while (std::getline(iss, item, delim)) {
  23. *result++ = item;
  24. }
  25. }
  26. std::vector<std::string> split(const std::string &s, char delim) {
  27. std::vector<std::string> elems;
  28. split(s, delim, std::back_inserter(elems));
  29. return elems;
  30. }
  31.  
  32. int st,dr,maxim;
  33. int lastst[20010],lastdr[20010];
  34. int main()
  35. {
  36.  
  37. ifstream fin("text3.in");
  38. ofstream fout("text3.out");
  39. string t;
  40. v.pb(" ");
  41. int poz;
  42. while(fin>>t)
  43. {
  44. int len=t.length();
  45. firstcount++;
  46. v.pb(t);
  47. st=v[firstcount][0]-'a';
  48. dr=v[firstcount][len-1]-'a';
  49. if(dp[st]+1>dp[dr])
  50. {
  51. dp[dr]=dp[st]+1;
  52. lastdr[i]=lastst[st];
  53. lastst[dr]=i;
  54. if(dp[dr]>maxim)
  55. {
  56. maxim=dp[dr];
  57. poz=i;
  58. }
  59. }
  60. }
  61. rez=maxim;
  62. fout<<firstcount<<"\n";
  63. fout<<firstcount-rez<<"\n";
  64. ans.pb(" ");
  65. while(poz)
  66. {
  67. ans.pb(v[poz]);
  68. poz=lastdr[poz];
  69. }
  70. for(i=rez;i>=1;i--)
  71. {
  72. fout<<ans[i]<<"\n";
  73. }
  74. fin.close();
  75. fout.close();
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement