0514 CF#798A Mike and palindrome
来源:互联网 发布:java 格式化当前时间 编辑:程序博客网 时间:2024/06/05 02:12
摘要:判断改变给定字符串的一个字符后,该字符串是否是回文。
题目链接:http://codeforces.com/contest/798/problem/A
A. Mike and palindrome
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
方法:计算前后对称位置处不同的字符有几个。 可以查一半,也可以全部查。查后分情况处理。
注意几种情况:
-1:已经对称的奇数串
-2:已经对称的偶数串
-3 :差一位回文的串
源代码:
#include<stdio.h>
#include<string.h>
int main()
{
char str[20];
scanf("%s",str);
int len=strlen(str);
int i;
int count=0;
for(i=0;i<len;i++)
{
if(str[i]!=str[len-1-i])
count++;
}
if(count==2 || (count==0 && len%2==1))
printf("YES\n");
else printf("NO\n");
return 0;
}
2017-5-14
0 0
- 0514 CF#798A Mike and palindrome
- CF- 798A. Mike and palindrome
- CF#798 A. Mike and palindrome(水题)
- A. Mike and palindrome
- A. Mike and palindrome
- codeforces 798a Mike and palindrome 水题
- CodeForces 798A Mike and palindrome
- Codeforces 798A -Mike and palindrome
- 小白题解 Codeforces 798A Mike and palindrome
- CF 547 A Mike and Frog
- A. Mike and Cellphone(cf#361)
- Codefroces 410 A. Mike and palindrome
- cf 798c Mike and gcd problem
- Codeforces798A-Mike and palindrome
- Codeforces798A Mike and palindrome
- Mike and palindrome
- cf#305-A. Mike and Fax-回文串水题
- Codeforces Round #410 (Div. 2)-A. Mike and palindrome-思维
- can not locate win32ui.pyd问题解决
- KairosDB 1.13安装手记
- ASP.NET经典权限解决方案,适用于OA、CRM、ERP、HR等应用系统
- APIO2017垫底记&THUPC2017划水记
- SSM配置Ueditor实现图片的上传<二>
- 0514 CF#798A Mike and palindrome
- 周末 20170514
- [PAT-乙级]1021.个位数统计
- 详解Java反射机制
- CentOS7 执行yum 命令出错
- Arrays.asList方法总结
- js中使用队列进行的基数排序
- MyBatis中批量插入
- [PAT-乙级]1022.D进制的A+B