Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- string s;
- vector<string>w,w2;
- vector<pair<int,int>>st;
- int mx=0;
- getline(cin,s);
- for(int i=0;i<(int)s.size();++i)
- if(isalpha(s[i]))
- {
- string _s="",sp="";
- while(isalpha(s[i]))
- _s+=s[i++];
- while(isspace(s[i]))
- sp+=s[i++];
- --i;
- w.push_back(_s);
- w2.push_back(_s+sp);
- }
- int lg=1;
- bool g=0;
- for(int i=0;i<(int)w.size();++i)
- if(i!=(int)w.size()-1&&w[i][w[i].size()-1]==w[i+1][0])
- ++lg,g=1;
- else
- {
- if(lg>mx&&g)
- st.clear(),st.push_back(make_pair(i-lg+1,i+1)),mx=lg;
- else
- if(lg==mx&&g)
- st.push_back(make_pair(i-lg+1,i+1));
- lg=1;
- g=0;
- }
- if(st.size()==0)
- {
- cout<<-1;
- return 0;
- }
- for(int i=0;i<(int)st.size();++i)
- {
- for(int j=st[i].first;j<st[i].second;++j)
- cout<<w2[j];
- cout<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement