Advertisement
a53

SirPlatou

a53
Jan 24th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. string s;
  7. vector<string>w,w2;
  8. vector<pair<int,int>>st;
  9. int mx=0;
  10. getline(cin,s);
  11. for(int i=0;i<(int)s.size();++i)
  12. if(isalpha(s[i]))
  13. {
  14. string _s="",sp="";
  15. while(isalpha(s[i]))
  16. _s+=s[i++];
  17. while(isspace(s[i]))
  18. sp+=s[i++];
  19. --i;
  20. w.push_back(_s);
  21. w2.push_back(_s+sp);
  22. }
  23. int lg=1;
  24. bool g=0;
  25. for(int i=0;i<(int)w.size();++i)
  26. if(i!=(int)w.size()-1&&w[i][w[i].size()-1]==w[i+1][0])
  27. ++lg,g=1;
  28. else
  29. {
  30. if(lg>mx&&g)
  31. st.clear(),st.push_back(make_pair(i-lg+1,i+1)),mx=lg;
  32. else
  33. if(lg==mx&&g)
  34. st.push_back(make_pair(i-lg+1,i+1));
  35. lg=1;
  36. g=0;
  37. }
  38. if(st.size()==0)
  39. {
  40. cout<<-1;
  41. return 0;
  42. }
  43. for(int i=0;i<(int)st.size();++i)
  44. {
  45. for(int j=st[i].first;j<st[i].second;++j)
  46. cout<<w2[j];
  47. cout<<'\n';
  48. }
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement