给定一个字符串.问是否可以通过添加一个字符将其变成回文串。
输入:一行由小写字母构成的字符串,长度不超过10。
输出:YES 或者NO
输入样例:testest
输出样例:YES
<span style="font-size:18px;">#include <iostream>
#include <string>
using namespace std;
bool fun(string str)
{
if (str.length() == 0) return true;
bool result = false;
int low = 0;
int high = str.length() - 1;
while (low < high && str[low] == str[high]) {
low++;
high--;
}
if (high <= low) {
result = true;
} else
{
if (high == low + 1) {
result = true;
} else
{
int temp_low = low;
int temp_high = high - 1;
while (temp_low < temp_high && str[temp_low] == str[temp_high]) {
temp_low++;
temp_high--;
}
if (temp_low >= temp_high) {
result = true;
} else
{
temp_low = low + 1;
temp_high = high;
while (temp_low < temp_high && str[temp_low] == str[temp_high]) {
temp_low++;
temp_high--;
}
if (temp_low >= temp_high) {
result = true;
} else
{
result = false;
}
}
}
}
return result;
}
int main(int argc, const char * argv[]) {
// insert code here...
string str;
cin >> str;
bool result = fun(str);
if (result) {
cout << "Yes" << endl;
} else
{
cout << "No" << endl;
}
return 0;
</span>