Codeforces Round #410 (Div.2) A.Mike and palindrome-模拟
来源:互联网 发布:广告阻拦软件 编辑:程序博客网 时间:2024/05/17 09:00
题目大意:
给定一个字符串,要求必须并且只能修改一个字符,问能否使字符串变为回文串。
题解:非常显然,你把这个串倒过来写一遍,然后和原串比较一下看有多少个位置是不一样的。
显然这是个偶数(因为每个不一样的地方都通缉了两次)
如果这个数字/2==1,那么可以。否则不行。
可是这样会WA。
原因是如果一个长度为奇数的回文串不用修改就是回文串,好像是不行的。但其实你可以修改中间那个字符,这样他还是回文串。
这个要特判一下。
代码:
//Codeforces Round #401 (Div.2) A.#include<iostream>#include<cstdio>#include<cstring>#define MAXN 100using namespace std;char s[MAXN];int main(){scanf("%s",s);int len=strlen(s),cnt=0;for(int i=0;i<len;i++)if(s[i]!=s[len-i-1]) cnt++;cnt/=2;if(cnt==0&&len%2==1){printf("YES\n");return 0;}if(cnt==1) printf("YES\n");else printf("NO\n");return 0;}
0 0
- Codeforces Round #410 (Div.2) A.Mike and palindrome-模拟
- Codeforces Round #410 (Div. 2)-A. Mike and palindrome-思维
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone ( 模拟 )
- Codeforces Round #305 (Div. 2) A. Mike and Fax
- Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax
- Codeforces Round #305 (Div. 2)--A. Mike and Fax
- Codeforces Round #305 (Div. 2)A. Mike and Fax
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone
- Codeforces Round #361 (Div. 2)A. Mike and Cellphone
- Codeforces Round #361 (Div.2) - A. Mike and Cellphone
- Codeforces Round #361 (Div. 2) 689A Mike and Cellphone
- Codeforces Round #410 (Div. 2) Mike and gcd problem 思维
- Codeforces Round #410 (Div. 2) Mike and distribution 思维
- CF-Codeforces Round #410 (Div. 2)-D-Mike and distribution
- Codeforces Round #410 (Div. 2) D. Mike and distribution 思维
- Codeforces Round #410 (Div. 2) D. Mike and distribution(贪心)
- CSN博客持之以恒勋章,想说爱你不容易
- java-File-mkdir与createNewFile的先后执行
- String源码解读
- 牛客网题目(三)
- xshell ssh密码保存
- Codeforces Round #410 (Div.2) A.Mike and palindrome-模拟
- JAVA实现旋转数组的最小数字问题(《剑指offer》)
- 部分网页无法打开/修复上网问题的终极方法
- 文章标题
- Android5.0沉浸式状态栏,以及动态改变状态栏颜色
- linux进程同步与通信(共享内存和信号量)
- asm_diskstring为空的情况下修改ASM设备名称,且不修改asm_diskstring
- VUE跨域设置:监听80端口
- 在linux上安装telnet