Codeforces Round #410 (Div. 2) 798 A Mike and palindrome

1.题目链接

http://codeforces.com/contest/798/problem/A

2.题面

A. Mike and palindrome
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.

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
Copy
abccaa
output
Copy
YES
input
Copy
abbcca
output
Copy
NO
input
Copy
abcda
output
Copy
YES

3.题意

输入一个字符串 改变一个字符 能形成回文就YES 不能就NO

4.思路

需要注意的就是如果是偶数的话 只能允许不相等数为一 如果是技术的话 可以为零 也可以为一 挺简单的题目

5.代码实现

[cpp] 
#include <bits/stdc++.h>
using namespace std;
char s[20];
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	int a=0;
	for(int i=0;i<len/2;i++)
	{
		if(s[i]==s[len-1-i])
		    continue;
		a++;
	}
	if(a==1||(a==0&&len%2))
	    printf("YES\n");
	else printf("NO\n");
	return 0;
}

view plain  cop

6.反思

最开始的忘了奇数完全相同也可以了 WA了两次 难受

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值