zoukankan      html  css  js  c++  java
  • Dual Palindromes



    Dual Palindromes
    Mario Cruz (Colombia) & Hugo Rickeboer (Argentina)

    A number that reads the same from right to left as when read from left to right is called a palindrome. The number 12321 is a palindrome; the number 77778 is not. Of course, palindromes have neither leading nor trailing zeroes, so 0220 is not a palindrome.

    The number 21 (base 10) is not palindrome in base 10, but the number 21 (base 10) is, in fact, a palindrome in base 2 (10101).

    Write a program that reads two numbers (expressed in base 10):

    • N (1 <= N <= 15)
    • S (0 < S < 10000)
    and then finds and prints (in base 10) the first N numbers strictly greater than S that are palindromic when written in two or more number bases (2 <= base <= 10).

    Solutions to this problem do not require manipulating integers larger than the standard 32 bits.

    PROGRAM NAME: dualpal

    INPUT FORMAT

    A single line with space separated integers N and S.

    SAMPLE INPUT (file dualpal.in)

    3 25

    OUTPUT FORMAT

    N lines, each with a base 10 number that is palindromic when expressed in at least two of the bases 2..10. The numbers should be listed in order from smallest to largest.

    SAMPLE OUTPUT (file dualpal.out)

    26
    27
    28 


    /*
        ID:qhn9992
        PROG:dualpal
        LANG:C++
    */

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <cstring>

    using namespace std;

    char cuan[100];

    void fun(int t,char cuan[],int base)
    {
        unsigned long long int res=0;
        char ts[10000];
        int cnt=0;
        while(t)
        {
            ts[cnt++]=(t%base)+'0';
            t/=base;
        }
        int cnt2=0;
        for(int i=cnt-1;i>=0;i--)
            cuan[cnt2++]=ts;
        cuan[cnt2]='';
    }

    bool ispali(int s,int d)
    {
        for(int i=s,j=d;i<j;i++,j--)
        {
            if(cuan==cuan[j]) ;
            else return false;
        }
        return true;
    }

    int main()
    {
        freopen("dualpal.in","r",stdin);
        freopen("dualpal.out","w",stdout);
        int n,s,t;
        scanf("%d%d",&n,&s);
        vector<int> v;
        t=s+1;
        while(n)
        {
            int cnt=0;
            for(int i=2;i<=10;i++)
            {
                fun(t,cuan,i);
                if(ispali(0,strlen(cuan)-1))
                {
                    cnt++;
                }
                if(cnt>=2)
                {
                    v.push_back(t);
                    n--;
                    break;
                }
            }
            t++;
        }
        for(int i=0;i<v.size();i++)
        {
            printf("%d ",v);
        }
        return 0;
    }
    * This source code was highlighted by YcdoiT. ( style: Codeblocks )
  • 相关阅读:
    【华为云技术分享】浅谈服务化和微服务化(上)
    STM32 GPIO的原理、特性、选型和配置
    【华为云技术分享】如何设计高质量软件-领域驱动设计DDD(Domain-Driven Design)学习心得
    【华为云技术分享】如何做一个优秀软件-可扩展的架构,良好的编码,可信的过程
    【华为云技术分享】华为云MySQL新增MDL锁视图特性,快速定位元数据锁问题
    如何使网站支持https
    如何说孩子才会听,怎么听孩子才肯说
    box-sizing布局学习笔记
    vertical-align属性笔记
    Github上整理的日常发现的好资源【转】
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350870.html
Copyright © 2011-2022 走看看