我这么写的,对照下吧
```cpp
#include<bits/stdc++.h>
using namespace std;
string a;
int k,p[22000005],ans;
char s[22000005];
void cz(){
s[k++]='&';
s[k++]='#';
for(int i=0;i<a.size();i++){
s[k++]=a[i];
s[k++]='#';
}
s[k++]='$';
}
void manacher(){
int r=0,c;
for(int i=1;i<k;i++){
if(i<r)
p[i]=min(p[2*c-i],c+p[c]-i);
else
p[i]=1;
while(s[i-p[i]]==s[i+p[i]])
++p[i];
if(r<i+p[i]){
r=i+p[i];
c=i;
}
}
}
int main(){
cin>>a;
cz();
manacher();
ans=1;
for(int i=0;i<k;i++){
ans=max(ans,p[i]);
}
cout<<ans-1;
return 0;
}
```
by so_find_skind @ 2023-08-02 12:32:15
@[Andy_L](/user/460429)
by so_find_skind @ 2023-08-02 12:32:23
不知道哎,不如学习珂学
by Dehydration @ 2023-08-02 12:32:34
不如学习珂学
by yingkeqian9217 @ 2023-08-02 12:32:53
@[zhezhikongdanruxue](/user/756179) 我开的比你的还大(
by Andy_L @ 2023-08-02 12:33:09
cz()就是你的read()
manacher()就是你主函数的那个循环
by so_find_skind @ 2023-08-02 12:33:14
@[zhezhikongdanruxue](/user/756179) string炸了,改成 char 数组就可以了
by Andy_L @ 2023-08-02 12:36:14