暴力循环,从j处向左右延伸,对称就继续延伸
注意:对称有两种,abccba abcba
#include<iostream>
#include<string>
#define jIN(x,y) for(int j=x;j<y;j++)
using namespace std;
int main(){
string s;
getline(cin,s);
int fi=1;
int x;//偏移量
int len=s.length();
jIN(0,len){
x=1;
while(j-x>=0 && j+x<len && s[j-x]==s[j+x] && x++);
fi=max(fi,x*2-1);
x=1;
while(j-x+1>=0 && j+x<len && s[j-x+1]==s[j+x] && x++);
fi=max(fi,(x-1)*2);
}
cout<<fi<<endl;
return 0;
}