Determines whether a number is a palindrom numbers in the 2-16 hexadecimal format.

Source: Internet
Author: User
Tags integer numbers

Statement of the problem

We say that a number is a palindrom if it is the sane when read from left to right or from right to left. For example, the number 75457 is a palindrom.

Of course, the property depends on the basis in which is number is represented. The number 17 is not a palindrom in base 10, but its representation in base 2 (10001) is a palindrom.

The objective of this problem is to verify if a set of given numbers are palindroms in any basis from 2 to 16.

Input Format

Several integer numbers comprise the input. Each number 0 <n <50000 is given in decimal basis in a separate line. The input ends with a zero.

Output Format

Your program must print the message number I is palindrom in basis where I is the given number, followed by the basis where the representation of the number is a palindrom. if the number is not a palindrom in any basis
2 and 16, your program must print the message number I is not palindrom.

Sample Input

17
19
0

Sample output

Number 17 is palindrom in basis 2 4 16
Number 19 is not a palindrom


// ================================================ ==================================================================== // Name: algorithm. CPP // Author: // version: // copyright: Your copyright notice // Description: Hello world in C ++, ANSI-style // ========================================== ========================================================== = # include <iostream> using namespace STD; int main () {int X; CIN> X; while (x) {bool ispali = false; char arr [30]; int base [17] = {0}; For (INT I = 2; I <= 16; I ++) {int temp = x; int Len = 0; while (temp) {arr [Len ++] = TEMP % I; temp/= I;} bool tag = true;/* For (Int J = 0, K = len-1; j <K; j ++, k --) {If (ARR [J]! = Arr [k]) {tag = false; break;} * // method 2 for (Int J = 0; j <Len/2 & tag; j ++) if (ARR [J]! = Arr [len-j-1]) Tag = false; If (TAG) {base [I] = 1; ispali = true ;}} if (! Ispali) cout <"Number" <x <"is not a palindrom" <Endl; else {cout <"Number" <x <"is palindrom in basis at:"; for (INT I = 2; I <= 16; I ++) {If (base [I]) cout <I <";}} CIN >>x;} return 0 ;}



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.