Codeforce A. Quasi-palindrome

A. Quasi-palindrome
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.

String t is called a palindrome, if it reads the same from left to right and from right to left.

For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.

You are given some integer number x. Check if it's a quasi-palindromic number.

Input

The first line contains one integer number x (1 ≤ x ≤ 109). This number is given without any leading zeroes.

Output

Print "YES" if number x is quasi-palindromic. Otherwise, print "NO" (without quotes).

Examples
input
131
output
YES
input
320
output
NO
input
2010200
output
YES

这题代码题;
枚举每个中间点就行了;

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;

char s[1008],flag;

int main(){
    scanf("%s",s);
    flag=-1;
    int len=strlen(s);
    for(int i=len-1;i>=0;i--)
        if(s[i]!='0'){
            flag=i;
            break;
        }
    for(int i=0;i<len;i++){
        int x=0;
        while(i-x>=0&&i+x<len&&s[i-x]==s[i+x]){
            x++;
        }
        if(i+x>flag&&i-x<0){
            printf("YES");
            return 0;
        }
    }
    for(int i=0;i<len;i++){
        int x=i,y=i+1;
        while(x>=0&&y<len&&s[x]==s[y]){
            x--; y++;
        }
        if(y>flag&&x<0){
            printf("YES");
            return 0;
        }
    }
    printf("NO");
}
原文地址:https://www.cnblogs.com/WQHui/p/7593875.html