题目链接

一个简单的题目,但是却很少有人可以一次AC,比如我就瞎写wa了一次。。。

写本博算个教训录吧。

题目给出一个字符串,让你严格的改变一个字符使改变后的字符串是一个回文串。

回文串不用解释了。不懂自行百度。

需要注意两点:

1.如果长度为偶数,并且事先就是一个回文串,那么要输出no的,因为必须要改变一个字符串,在原本就是回文的基础上改变一下就不是回文串了。

2.如果长度为奇数,并且事先就是一个回文串,那么要输出yes,因为可以只改变最中间的那个字符,改后还是一个回文串。

其他的就是判断有几对字符不一样了,是一对的话就yes,不是就no。

我的AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb std::ios::sync_with_stdio(false)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=;
/*** TEMPLATE CODE * * STARTS HERE ***/
char s[maxn]; int main()
{
scanf("%s",s);
int len=strlen(s);
int l=;
int cnt=;
int r=len-;
while(l<=r)
{
if(s[l]!=s[r])
{
cnt++;
}
l++;
r--; }
if(cnt==||(cnt==&&(len%==)))
printf("YES\n");
else
printf("NO\n");
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

Mike and palindrome CodeForces - 798A的更多相关文章

  1. Codeforces 798A - Mike and palindrome

    A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. 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 ...

  3. 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 ...

  4. CF410div2 A. Mike and palindrome

    /* CF410div2 A. Mike and palindrome http://codeforces.com/contest/798/problem/A 水题 */ #include <c ...

  5. 【codeforces 798A】Mike and palindrome

    [题目链接]:http://codeforces.com/contest/798/problem/A [题意] 让你严格改变一个字符,使得改变后的字符串为一个回文串; 让你输出可不可能; [题解] 直 ...

  6. Make Palindrome CodeForces - 600C(思维)

    A string is called palindrome if it reads the same from left to right and from right to left. For ex ...

  7. Mike and Feet CodeForces - 548D (单调栈)

    Mike is the president of country What-The-Fatherland. There are n bears living in this country besid ...

  8. Mike and distribution CodeForces - 798D (贪心+思维)

    题目链接 TAG: 这是我近期做过最棒的一道贪心思维题,不容易想到,想到就出乎意料. 题意:给定两个含有N个正整数的数组a和b,让你输出一个数字k ,要求k不大于n/2+1,并且输出k个整数,范围为1 ...

  9. Mike and strings CodeForces - 798B (简洁写法)

    题目链接 时间复杂度 O(n*n*|s| ) 纯暴力,通过string.substr()函数来构造每一个字符串平移后的字符串. #include <iostream> #include & ...

随机推荐

  1. MySQL复制错误1837的相关缺陷一例

    故障现象 主从gtid报错,复制错误1837,这个复制故障可以说是第一次遇到. Last_Errno: 1837 Last_Error: Error 'When @@SESSION.GTID_NEXT ...

  2. 函数指针的返回值是指针数组,数组里放的是int;函数指针的返回值是指针数组,数组里放的是int指针

    函数指针的返回值是指针数组,数组里放的是int 函数指针的返回值是指针数组,数组里放的是int指针 #include <stdio.h> #include <stdlib.h> ...

  3. MapFileParser.sh: Permission denied

    Unity项目,需要用Xcode运行,结果报了错误. 解决方案: 1.打开终端, 2.输入以下命令: chmod +x   /Users/......./MapFileParser.sh (MapFi ...

  4. mybatis中使用Integer类型的参数<if>判断问题

    mybatis对传入参数进行判断时,会使用if标签, 一般是判断不为null和'', 如下: <if test="name != null and 那么 != ''"> ...

  5. Java程序导出成.jar文件、生成.exe可执行文件及打包成可执行安装程序(可在无Java环境的计算机上运行)--以个人所得税计算器为例

    Java程序导出成.jar文件.生成.exe可执行文件及打包成可执行安装程序 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 需要准备的软件: jdk, ...

  6. keepalived 安装篇-官方文档

    官方安装文档 http://www.keepalived.org/doc/installing_keepalived.html Installing Keepalived Install keepal ...

  7. 解决Go依赖包安装问题

    最近在学习Go编写后端服务,先放出谢大的书镇楼: https://github.com/astaxie/build-web-application-with-golang/blob/master/zh ...

  8. tape ——cf

    B. Tape time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  9. CMD命令行netsh添加防火墙规则

    1.为e:\f.exe 添加防火墙规则(参考:https://www.cnblogs.com/zhen656/p/4275270.html),需要管理员权限. >netsh advfirewal ...

  10. AI 概率图模型

    概率图模型(Probabilistic Graphical Model) 有向图模型 信念网络 贝叶斯网络 无向模型 马尔科夫随机场 马尔科夫网络