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 <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
string s;
int main(){
cin >> s;
bool ans=0;
if(s.size()==1) ans = 1;
if(s.size()&1){
bool f=0;
for(int j=0,k=s.size()-1; j<k; j++,k--){
if(s[j]!=s[k]){
f=1;
break;
}
}
if(!f) ans = 1;
}
for(int i=0; i<s.size(); i++){
string t=s;
// if(s.size()&1){
// if(i==s.size()/2+1) continue;
// }
if(i<s.size()/2){
if(t[i] != s[s.size()-i-1]){
t[i] = s[s.size()-i-1];
}
else continue;
}
else {
if(t[i] != s[s.size()-1-i]) t[i] = s[s.size()-1-i];
else continue;
}
// cout << t<<endl;
bool f=0;
for(int j=0,k=t.size()-1; j<k; j++,k--){
if(t[j]!=t[k]){
f=1;
break;
}
}
if(!f) {
ans = 1;
break;
}
}
if(ans) puts("YES");
else puts("NO");
return 0;
}