//分奇偶从中心向两边扩展判断回文即可
#include<iostream>
using namespace std;
string str;
int MAX, index;
void solution(int, int);
int main(){
while(getline(cin, str)){
if(str == "#"){
break;
}
MAX = 0, index = 0;
for(int i = 0; i < str.length() - 1; i++){
solution(i, i + 1);
solution(i, i);
}
cout << str.substr(index, MAX) << endl;
}
return 0;
}
void solution(int left, int right){
while(left >= 0 && right < str.length()){
if(str[left] == str[right]){
left--;
right++;
}else{
break;
}
}
if(MAX < right - left - 1){
MAX = right - left - 1;
index = left + 1;
}
}
//presented by 大吉大利。今晚AC
合肥工业大学oj 1232 Hi,there ereht,iH
猜你喜欢
转载自blog.csdn.net/lalala_HFUT/article/details/87967306
今日推荐
周排行