Codeforces Round #410 (Div. 2) A
2024-08-28 08:33:55
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
题意:必须修改一次字符串中的字符,问能不能成为回文串
解法:模拟,注意必须要修改字符
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=;
string s,ss,sss,ssss,s1;
int main()
{
cin>>s;
for(int i=;i<s.size();i++)
{
ss=s;
for(int j=;j<;j++)
{
ss[i]='a'+j;
if(s[i]==ss[i]) continue;
sss=ss;
ssss=ss;
reverse(sss.begin(),sss.end());
if(ssss==sss)
{
cout<<"YES";
return ;
} }
}
cout<<"NO"<<endl;
return ;
}
最新文章
- 通过设置CSS属性让DIV水平居中
- Python黑帽编程 4.0 网络互连层攻击概述
- ENode 2.0 - 第一个真实案例剖析-一个简易论坛(Forum)
- ASP文件操作(FSO)详解
- PHP程序员的40点陋习,我几乎全部中枪
- Write a beautiful button
- ACM_基础知识
- jQuery Ajax无刷新操作
- struts2 表单处理
- Android中ListView通过BaseAdapter实现数据的绑定
- CentOS7 安装LNMP(Linux+Nginx+MySQL+PHP)
- hive函数总结-字符串函数
- windows系统npm如何升级自身
- C#、VB.NET 使用System.Media.SoundPlayer播放音乐
- SpringMVC中采用简洁的配置实现文件上传
- int-整数+bool-布尔功能介绍
- VS 2008 开发WinCE程序 编译部署速度慢的解决办法
- Oarcle 之连接查询
- Hibernate入门(四)---------一级缓存
- 本博客停止更新改用wordperss