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 )
  • 相关阅读:
    转载:[Java面经]干货整理, Java面试题(覆盖Java基础,Java高级,JavaEE,数据库,设计模式等)
    转载:《理解OAuth 2.0》 阮一峰
    转载:《RESTful API 设计指南》 阮一峰
    转载:《理解RESTful架构》 阮一峰
    转载:2.2.5 在配置中使用变量《深入理解Nginx》(陶辉)
    转载:2.2.4 配置项的单位《深入理解Nginx》(陶辉)
    转载:2.2.3 配置项的注释《深入理解Nginx》(陶辉)
    SQL & PL/SQL 模块总结
    一些比较好的shellscript脚本
    11 高级优化技术
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350870.html
Copyright © 2011-2022 走看看