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.
The first and single line contains string s (1 ≤ |s| ≤ 15).
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Input
abccaa
Output
YES
Input
abbcca
Output
NO
Input
abcda
Output
YES
以为注意了数组长度为1时就会不被坑了,怎知,还有当字符串是回文时并长度为奇数是也是符合的。
#include<bits/stdc++.h>
using namespace std;
int main()
{
char c[16];
while(scanf("%s",&c)!=EOF)
{
int len = strlen(c);
int n=0;
for(int i=0;i<len;i++)
{
if(c[i]!=c[len-i-1])
n++;
}
if(len==1)
printf("YES\n");
else
{
if(n==2)
printf("YES\n");
else
if(n==0&&len%2!=0)
printf("YES\n");
else
{
printf("NO\n");
}
}
}
return 0;
}