直接双指针枚举,然后直接用stl(hh)
include
include
include
using namespace std;
string s;
int res = 1;
int main(){
char c;
while(scanf("%c",&c) != EOF){
s.push_back(c);
}
for(int i = 0; i < s.size(); i++){
for(int j = i + 1; j < s.size(); j++){
string s1,s2;
if((j-i+1) % 2 == 0){
s1 = s.substr(i, (j-i+1)/2);
s2 = s.substr(i+(j-i+1)/2, (j-i+1)/2);
reverse(s2.begin(),s2.end());
}
else{
s1 = s.substr(i, (j-i)/2);
s2 = s.substr(i+(j-i)/2+1, (j-i)/2);
reverse(s2.begin(),s2.end());
}
if(s1 == s2) res = max(res,j-i+1);
}
}
cout << res;
return 0;
}