#include<iostream>
using namespace std;
string s;
int fun(int a, int b){
while(a < b){
if (s[a++] != s[b--]) return 0;
}
return 1;
}
int main(){
getline(cin, s);
int step, cnt = 1;
for (step = 2; step <= s.size(); step++){ //改良的分步长遍历;
for (int i = 0; i + step - 1 < s.size(); i++){
int j = i + step - 1;
if (fun(i, j) == 1){
cnt = step;
}
}
}
cout << cnt;
// for (int i = 0; i < s.size(); i++){ //低效率的双向遍历,无法通过两个测点;
// for (int j = s.size() - 1; j > i; j--){
// if (fun(i, j) == 1){
// cout << j - i + 1;
// return 0;
// }
// }
// }
// cout << 1;
}
PAT甲级1040
最新推荐文章于 2021-11-16 15:12:17 发布