思路:两个指针,一个从左往右,一个从右往左,只能跳过一次,第二次的时候及说明需要添加两个字符
include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
while (cin>>str)
{
bool flag = true;
bool move = true;
int left = 0;
int right = str.length() - 1 ;
while (left< str.length() / 2 && right>= str.length() / 2)
{
if (str[left] == str[right])
{
left++;
right--;
}
else if (right - 1 >= 0 && str[left] == str[right - 1] && move==true)
{
right--;
move = false;
}
else if (left + 1 >= 0 && str[left+1] == str[right ] && move == true)
{
left++;
move = false;
}
else
{
flag = false;
break;
}
}
if (flag == false)
{
cout << "NO" << endl;
}
else
{
cout << "YES" << endl;
}
}
return 0;
}