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 }
  • 相关阅读:
    【转】PowerManager 与 WakeLock
    【转】设计模式总结之模式分类
    【转】一篇文章,教你学会Git
    【转】Iconfont
    【转】码云source tree 提交超过100m 为什么大文件推不上去
    各 Android 平台版本支持的 API 级别
    【转】Android进程机制
    【转】数据库CRUD操作
    【转】数据库--视图的基本概念以及作用
    动态规划的两种形式
  • 原文地址:https://www.cnblogs.com/shangyu/p/2651439.html
Copyright © 2011-2022 走看看