Codeforces 798A - Mike and palindrome
2 seconds
256 megabytes
standard input
standard output
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.
The first and single line contains string s (1 ≤ |s| ≤ 15).
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
abccaa
YES
abbcca
NO
abcda
YES
题目大意:是否可以改变一个字符,使得字符串恰好为回文串。
方法:检查字符串是否为回文,记录不同记录不同位点个数。如果字符串不是回文,且不同位点为一个,输出YES;如果位点为0(也就是回文串)且串长度为奇数(可以改变最中间的那个),则输出YES;如果前两条都不满足,输出NO。
代码:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=;
int main()
{
ios::sync_with_stdio(false);
cin.tie();
char s[N];
gets(s);
int cnt=;
for(int i=;i<strlen(s);i++)
{
if(s[i]!=s[strlen(s)-i-])cnt++;
}
if(cnt==)cout<<"YES"<<endl;
else
{
if(cnt==&&strlen(s)%)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return ;
}
Codeforces 798A - Mike and palindrome的更多相关文章
- Codeforces Round #410 (Div. 2) A. Mike and palindrome
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #410 (Div. 2) A. Mike and palindrome【判断能否只修改一个字符使其变成回文串】
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- CF410div2 A. Mike and palindrome
/* CF410div2 A. Mike and palindrome http://codeforces.com/contest/798/problem/A 水题 */ #include <c ...
- hdu4135-Co-prime & Codeforces 547C Mike and Foam (容斥原理)
hdu4135 求[L,R]范围内与N互质的数的个数. 分别求[1,L]和[1,R]和n互质的个数,求差. 利用容斥原理求解. 二进制枚举每一种质数的组合,奇加偶减. #include <bit ...
- codeforces 547E Mike and Friends
codeforces 547E Mike and Friends 题意 题解 代码 #include<bits/stdc++.h> using namespace std; #define ...
- codeforces 689 Mike and Shortcuts(最短路)
codeforces 689 Mike and Shortcuts(最短路) 原题 任意两点的距离是序号差,那么相邻点之间建边即可,同时加上题目提供的边 跑一遍dijkstra可得1点到每个点的最短路 ...
- 【codeforces 798A】Mike and palindrome
[题目链接]:http://codeforces.com/contest/798/problem/A [题意] 让你严格改变一个字符,使得改变后的字符串为一个回文串; 让你输出可不可能; [题解] 直 ...
- Mike and palindrome CodeForces - 798A
题目链接 一个简单的题目,但是却很少有人可以一次AC,比如我就瞎写wa了一次... 写本博算个教训录吧. 题目给出一个字符串,让你严格的改变一个字符使改变后的字符串是一个回文串. 回文串不用解释了.不 ...
- Codeforces 548B Mike and Fun
传送门 B. Mike and Fun time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 分页Bootstrap实现
<%@ include file="/init.jsp" %> <script type="text/javascript" src=&quo ...
- jquery控制css的display属性(显示与隐藏)
jquery控制div的显示与隐藏,很方便的. 例如: $("#id").show()表示display:block, $("#id").hide()表示dis ...
- VS中出现“链接器工具错误,XXX工具模块对于SAFESEH映像是不安全的”的解决方法
1.“调试”菜单->“属性”->“配置属性”->“链接器”->“命令行” 2.在“其它选项”的输入框里输入 /SAFESEH:NO ,点击“应用”
- kendo 级联加带搜索的下拉框以及js赋值
1‘.js给下拉框赋值 $("#UserRole").data("kendoDropDownList").value(dataItem.RoleName); $ ...
- ExtJs中XTemplate使用(转)
转自http://www.studyofnet.com/news/408.html 本文导读:XTemplate是Ext.Template扩展的新类,它支持高级功能的模板类,如自动数组输出.条件判断. ...
- java tar.gz文件生成
/** * 压缩文件成Gzip格式,Linux上可使用 * 压缩文件夹生成后缀名为".gz"的文件并下载 * @param folderPath,要压缩的文件夹的路径 * @par ...
- MFC Ribbon界面设计
Ribbon是类似于office2007样式的界面,它替代了传统的MFC程序里的菜单和工具栏 MFC默认生成的Ribbon功能少,需要我们自己添加一些控件和图片等元素使界面好看 看下面的一个界面,是V ...
- 文件系统、服务、防火墙、SELINUX——安全四大金刚
一提到安全,大家都会想到防火墙,和文件系统权限.而实际工作环境中,我们在Linux的安全配置,会涉及到四个级别.我们思考一个场景,你要在百度盘中存放一个文件,这个动作需要考虑下面四个权限. 1 fir ...
- 安装OpenOffice
附件: OpenOffice 1.下载解压 tar -zxvf Apache_OpenOffice_4.1.3_Linux_x86-64_install-rpm_zh-CN.tar.gz 2.安装 / ...
- 面向对象第一话,大战java正则表达式
本周我们迎来第一项任务,java面向对象之实现对一串字符的匹配以及构造出计算的多项式,最终得出计算的结果.简而言之,可以用以下的要求来看题目: 输入的多项式字符串中不得出现非法字符 多项式的输入型式, ...