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");
    }
  • 相关阅读:
    算法 在连续线性空间里查找
    OSI网络模型和网络连接设备
    CPU 架构SMP/NUMA,调优
    cluster集群基本概念
    protocol buffers 使用方法
    Qt在window下的环境变量PATH的配置
    mysql connector c++ 1.1 API初步体验
    mysql connector c++ 1.1 安装
    python知识点总结01(不定时更新)
    ant-design表单自定义验证
  • 原文地址:https://www.cnblogs.com/WQHui/p/7593875.html
Copyright © 2011-2022 走看看