Codeforces Round #410 (Div. 2) A

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
题意:必须修改一次字符串中的字符,问能不能成为回文串
解法:模拟,注意必须要修改字符
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define ll long long
 4 const int maxn=54321;
 5 string s,ss,sss,ssss,s1;
 6 int main()
 7 {
 8     cin>>s;
 9     for(int i=0;i<s.size();i++)
10     {
11         ss=s;
12         for(int j=0;j<26;j++)
13         {
14             ss[i]='a'+j;
15             if(s[i]==ss[i]) continue;
16             sss=ss;
17             ssss=ss;
18             reverse(sss.begin(),sss.end());
19             if(ssss==sss)
20             {
21                 cout<<"YES";
22                 return 0;
23             }
24 
25         }
26     }
27     cout<<"NO"<<endl;
28     return 0;
29 }

 

posted @ 2017-04-22 23:53  樱花落舞  阅读(190)  评论(0编辑  收藏  举报