Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <bits/stdc++.h>
- #include <map>
- #define pb push_back
- #define ll long long
- #define pii pair<int,int>
- #define pll pair<long,long>
- using namespace std;
- int rez;
- vector<string> ans;
- vector<string> v;
- int dp[28];
- int i,j,k,index=0,firstcount=0;
- vector<vector<string> > mat;
- template <typename Out>
- void split(const std::string &s, char delim, Out result) {
- std::istringstream iss(s);
- std::string item;
- while (std::getline(iss, item, delim)) {
- *result++ = item;
- }
- }
- std::vector<std::string> split(const std::string &s, char delim) {
- std::vector<std::string> elems;
- split(s, delim, std::back_inserter(elems));
- return elems;
- }
- int st,dr,maxim;
- int lastst[20010],lastdr[20010];
- int main()
- {
- ifstream fin("text3.in");
- ofstream fout("text3.out");
- string t;
- v.pb(" ");
- int poz;
- while(fin>>t)
- {
- int len=t.length();
- firstcount++;
- v.pb(t);
- st=v[firstcount][0]-'a';
- dr=v[firstcount][len-1]-'a';
- if(dp[st]+1>dp[dr])
- {
- dp[dr]=dp[st]+1;
- lastdr[i]=lastst[st];
- lastst[dr]=i;
- if(dp[dr]>maxim)
- {
- maxim=dp[dr];
- poz=i;
- }
- }
- }
- rez=maxim;
- fout<<firstcount<<"\n";
- fout<<firstcount-rez<<"\n";
- ans.pb(" ");
- while(poz)
- {
- ans.pb(v[poz]);
- poz=lastdr[poz];
- }
- for(i=rez;i>=1;i--)
- {
- fout<<ans[i]<<"\n";
- }
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement