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
    
    跟上个题类似啊 这个数 能用两个不同的进制表示成回文串 就输出
    View Code
     1 /*
     2   ID: your_id_here
     3   LANG: C++
     4   TASK: dualpal
     5   */
     6 #include <iostream>
     7 #include<cstdio>
     8 #include<string.h>
     9 using namespace std;
    10 char sq[301];
    11 int base(int y,int n)
    12  {
    13      int i = 0,j = 0,t,k,flag = 1;
    14      while(y)
    15      {
    16          t = y%n;
    17          if(t>=10)
    18          sq[++j] = t-10+'A';
    19          else
    20          sq[++j] = t+'0';
    21          y = y/n;
    22      }
    23      for(k = 1; k <= j/2 ;k++)
    24      {
    25          if(sq[k]!=sq[j-k+1])
    26          {
    27              flag = 0;
    28              break;
    29          }
    30      }
    31      return flag;
    32  }
    33 int main()
    34 {
    35     freopen("dualpal.in","r",stdin);
    36     freopen("dualpal.out","w",stdout);
    37     int i,j,k =0,n,m,s,num = 0;
    38     scanf("%d%d",&n,&s);
    39     for(i = s+1 ; ; i++)
    40     {
    41         k = 0;
    42         for(j = 2; j <= 10 ; j++)
    43         {
    44             if(base(i,j))
    45             {
    46                 k++;
    47             }
    48             if(k==2)
    49             {
    50                 num++;
    51                 printf("%d\n",i);
    52                 break;
    53             }
    54         }
    55         if(num>=n)
    56         break;
    57     }
    58     fclose(stdin);
    59     fclose(stdout);
    60     return 0;
    61 }
  • 相关阅读:
    CentOS 7 如何设置默认启动方式为命令行模式
    Virtual Box配置CentOS7网络
    序列化后成对象转map,再添加到dataList
    centos7 ping: www.baidu.com: Name or service not known
    协议1
    idea查看接口方法实现
    centos关闭防火墙
    myeclipse配置svn
    eas固定ip避免多次申请许可
    jvm配置
  • 原文地址:https://www.cnblogs.com/shangyu/p/2651439.html
Copyright © 2011-2022 走看看