Description
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
input
abccaa
output
YES
input
abbcca
output
NO
input
abcda
output
YES
题意:必须修改一次字符串中的字符,问能不能成为回文串
解法:模拟,注意必须要修改字符
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=;
string s,ss,sss,ssss,s1;
int main()
{
cin>>s;
for(int i=;i<s.size();i++)
{
ss=s;
for(int j=;j<;j++)
{
ss[i]='a'+j;
if(s[i]==ss[i]) continue;
sss=ss;
ssss=ss;
reverse(sss.begin(),sss.end());
if(ssss==sss)
{
cout<<"YES";
return ;
} }
}
cout<<"NO"<<endl;
return ;
}