Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char const *argv[])
- {
- string s;
- cin>>s;
- string t=s;
- reverse(all(t));
- string a=t+'#'+s;
- //cout<<a<<"\n";
- int n=sz(a);
- vector<int> p(n);
- int i=1,j=0;
- p[0]=0;
- for(int i=1;i<n;){
- // cout<<i<<" "<<j<<"\n";
- if(a[i]==a[j]){
- p[i]=j+1;
- ++i;
- ++j;
- }
- else{
- if(j>0)j=p[j-1];
- else{
- p[i]=0;
- ++i;
- }
- }
- }
- int l=sz(s)-p[n-1];
- //cout<<p[n-1]<<"\n";
- cout<<s;
- int co=0;
- while(co<l){
- cout<<s[l-co-1];
- ++co;
- }
- cout<<"\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement