居然没超时。。。
最笨的方法。。。
不过字符串长度1000以内,而且判断字串是否是回文串,如果不是就跳出,这样应该不会花多少时间,字串大多数情况都是首尾直接就不相等
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<set>
using namespace std;
string s;
int symlen(int low, int high){
int i = low;
int j = high;
while(i <= j){
if(s[i++] != s[j--]){
return 0;
}
}
return high - low + 1;
}
int main(){
getline(cin,s);
int maxlen = 0;
for(int i = 0; i < s.size(); i++){
for(int j = i; j < s.size(); j++){
int temp = symlen(i,j);
if(maxlen < temp) maxlen = temp;
}
}
cout<<maxlen;
return 0;
}