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 )
  • 相关阅读:
    石头汤
    win8激活 DNS名称不存在
    IE系列hack
    CSS缩写
    MSDN资源
    项目管理之软件文档知多少
    jqModal
    Microsoft Security Essentials 不升级方法
    XP没有声音服务解决方案
    office2003安全模式启动,默认模板问题/打开word就显示“无法装载这个对象”
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350870.html
Copyright © 2011-2022 走看看