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 }
  • 相关阅读:
    CSS强制换行
    Android 软件开发的盈利模式
    比较Collection 和Collections的区别
    Jsp 中taglib标签的妙用
    常用搜索引擎大全
    Jsp 中登陆界面的实现方法
    Jsp 中JavaScript 和 Java代码的异步执行特点
    Jsp struts 标准配置测试版
    div demo
    多线程模拟银行业务调度系统
  • 原文地址:https://www.cnblogs.com/shangyu/p/2651439.html
Copyright © 2011-2022 走看看