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 }

 

转载于:https://www.cnblogs.com/yinghualuowu/p/6750337.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值