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 @   樱花落舞  阅读(193)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示