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 )
  • 相关阅读:
    MS MDS系列之MDS层次结构(Hierarchy)
    Tabular系列之问题1:如何利用其他人的账号进行权限测试?
    MS MDS系列之初识MS Master Data Service(微软主数据服务)
    SQL Server系列之SQL Server 2016 中文企业版详细安装步骤(超多图)
    Pivot Table系列之切片器 (Slicer)
    Pivot Table系列之展开/折叠用法 (Expand/Collapse)
    MyBatis逆向工程——Java代码自动生成
    汇智网练习:修改示例代码,使EzApp组件的标题颜色每秒钟随机变化一次
    关于事件模型,js事件绑定和解除的学习
    使用block进行界面之间的反向传值
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350870.html
Copyright © 2011-2022 走看看