Usaco--dual Palindromes Double palindrome number

Source: Internet
Author: User
Description

If a number is read from left to right and from right to left, then this number is called "palindrome number". For example, 12321 is a palindrome number, and 77778 is not. Of course, the first and the end of a palindrome number should be nonzero, so 0220 is not a palindrome number.

In fact, there are some numbers (such as 21), which are not palindrome numbers in decimal, but are palindrome when other binary (such as 10101 at binary).

To compile a program, read from the file two decimal numbers n (1 <= n <=) S (0 < S < 10000) and then find out the first N is greater than s and in two or more binary (binary to decimal) is a palindrome number of decimal number, output to the file.

The solution for this problem does not require the use of integers larger than 32 bits
Format

Program NAME: Dualpal

INPUT FORMAT:

(File dualpal.in)

Only one row, separated by a space of two numbers n and S.

OUTPUT FORMAT:

(File dualpal.out)

n rows, one per line satisfies the above requirements, and outputs in order from small to large.
SAMPLE INPUT
3
SAMPLE OUTPUT

262728

#include <fstream>
using namespace std;
Ifstream cin ("dualpal.in");
Ofstream cout ("Dualpal.out");
int ini_t (int x,int B)
{
   int a[20];
   int b[20];
   int l=0;
   while (x!=0)
   {
      a[++l]=x%b;
      x/=b;            
   }
   for (int i=1;i<=l/2;i++)
   {
       if (A[i]!=a[l+1-i]) return 0;
   }
   return 1;
}
int main ()
{
   int n,s;
   cin>>n>>s;
   int y=0;
   for (int i=s+1;; i++)
   {
       int j1=0;
       for (int j=2;j<=10;j++)
       {
           if (ini_t (i,j) ==1) j1++;
           if (j1==2) break;
       }       
       if (j1==2) {Y++;cout<<i<<endl;}
       if (y==n) break;
   }
   System ("pause");
   return 0;    
} 


Simulation questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.