One day, sailormoon girls are so delighted that they intend to research about palindromic strings. Operation contains two steps:
First step: girls will write a long string (only contains lower case) on the paper. For example, "abcde", but 'a' inside is not the real 'a', that means if we define the 'b' is the real 'a', then we can infer that 'c' is the real 'b', 'd' is the real 'c' ……, 'a' is the real 'z'. According to this, string "abcde" changes to "bcdef".
Second step: girls will find out the longest palindromic string in the given string, the length of palindromic string must be equal or more than 2.
题意:有一个字符串,先将它进行循环映射,再求其中最长的回文子串,长度至少大于等于2
manacher裸题
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int maxn=2e5+;
char s[maxn],t[maxn<<];
char res[maxn];
int p[maxn<<]; void manacher(){
int len=strlen(s),l=;
t[l++]='$';
t[l++]='#';
for(int i=;i<len;++i){
t[l++]=s[i];
t[l++]='#';
}
t[l]=;
int maxx=,num=;
for(int i=;i<l;++i){
p[i]=maxx>i?min(p[*num-i],maxx-i):;
while(t[i+p[i]]==t[i-p[i]])p[i]++;
if(i+p[i]>maxx){
maxx=i+p[i];
num=i;
}
}
} int main(){
char c[];
while(scanf("%s%s",c,s)!=EOF){
int l=strlen(s);
for(int i=;i<l;++i){
s[i]='a'+(s[i]-c[]+)%;
}
manacher();
int pos=,ans=;
for(int i=;i<*l+;++i){
if(p[i]->ans){
pos=i;ans=p[i]-;
}
}
int ans1=0x3f3f3f3f,ans2=,cnt=;
for(int i=pos-p[pos]+;i<=pos+p[pos]-;++i){
if(t[i]!='#'){
res[cnt++]=t[i];
if(i<ans1)ans1=i;
if(i>ans2)ans2=i;
}
}
res[cnt]=;
if(p[pos]->){
printf("%d %d\n",(ans1-)/,(ans2-)/);
printf("%s\n",res);
}
else printf("No solution!\n");
}
return ;
}