zoukankan      html  css  js  c++  java
  • 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");
    }
  • 相关阅读:
    在python3.7下怎么安装matplotlib与numpy
    kNN(从文本文件中解析数据)
    k-近邻算法(kNN)笔记
    第二章--k-近邻算法(kNN)
    C++学习笔记一 —— 两个类文件互相引用的处理情况
    (转) C++中基类和派生类之间的同名函数的重载问题
    初试 Matlab 之去除水印
    (转) linux之sort用法
    vim 简单配置
    hdu 5358 First One
  • 原文地址:https://www.cnblogs.com/WQHui/p/7593875.html
Copyright © 2011-2022 走看看