标签:manacher
#include<stdio.h> #include<string.h> #define MAX 200020 char s[MAX],ss[MAX*2],str[2]; int p[MAX*2]; int chance(char s) { return (s- str[0] + 26) % 26 + 'a'; } int min(int a,int b){return a>b?b:a;} int main() { int i,id,mx,max,n,j,ans,m; while(scanf("%s%s",str,s)!=EOF) { ss[0]='$'; n=strlen(s); for(i=0;i<n;i++) { ss[2*i+1]='#'; ss[2*(i+1)]=s[i]; } ss[2*i+1]='#'; ss[2*(i+1)]='\0'; id=1; max=0; mx=0; for(i=1;i<2*n+2;i++) { if(mx>i) p[i]=min(p[2*id-i],mx-i); else p[i]=1; while(ss[i+p[i]]==ss[i-p[i]]) { p[i]++; } if(i+p[i]>mx) { mx=i+p[i]; id=i; } if(p[i]>max) {j=i; max=p[i];} } if(max-1<2) printf("No solution!"); else { if(j%2) ans=(j/2-(max-1)/2)+1; else ans=j/2-(max-1)/2; m=j/2+(max-1)/2; printf("%d %d\n",ans-1,m-1); for(i=ans-1;i<m;i++) printf("%c",chance(s[i])); printf("\n"); } } return 0; }
标签:manacher
原文地址:http://blog.csdn.net/lihaogegehuting/article/details/37943227