您的位置:首页 > 其它

CF- 798A. Mike and palindrome - 思维

2017-04-22 21:01 375 查看
1.题目描述:

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
abccaa


output
YES


input
abbcca


output
NO


input
abcda


output
YES


2.题意概述:

定义一个变量是合法的当且仅当它回文。给你一个字符串,麦克一定要修改其中一个字符,问你是否存在某种修改使得它成为一个变量。

3.解题思路:

坑的地方在于它一定会修改一次,因此如果字符串本身就是回文的且为偶数串则不管怎么修改它都不再是回文串,注意这个地方应该就没有坑点了。

4.AC代码:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100100
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
char s[20];
int main()
{
scanf("%s",s);
int len=strlen(s);
int temp=0;
for(int i=0;i<len/2;i++)
{
if(s[i]==s[len-1-i])
continue;
temp++;
}
if(temp==1||(temp==0&&len%2))
printf("YES\n");
else printf("NO\n");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm 算法 codeforces