Palindrom Numbers 任意进制数转换
2013-11-29 15:05
190 查看
Palindrom Numbers
Time Limit: 2 Seconds Memory Limit: 65536 KB
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 between 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
Time Limit: 2 Seconds Memory Limit: 65536 KB
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 between 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
#include <iostream> #include <cstring> #include<cmath> using namespace std; short int b[50000],d[50000],r[50000]; int main() { int a; while(cin>>a&&a) { int i,m,c,p=0; memset(r,0,sizeof(r)); for(i=2;i<=16;++i) { memset(b,0,sizeof(b)); m=a; c=0; while(m) { b[c++]=m%i; m=m/i; } int j,k=0; for(j=c-1;j>=0;--j) { d[k++]=b[j]; } for(j=0;j<c;++j) { if(b[j]!=d[j]) break; } if(j==c) r[p++]=i; } if(p==0) cout<<"Number "<<a<<" is not a palindrom"<<endl; else { cout<<"Number "<<a<<" is palindrom in basis "; for(int j=0;j<p;j++) { cout<<r[j]; if(j==p-1) cout<<endl; else cout<<" "; } } } return 0; }
相关文章推荐
- 利用python实现任意进制的相互转换
- POJ 1220-NUMBER BASE CONVERSION 任意进制数转换
- php任意进制转换base_convert()
- 任意进制间的转换(用c语言实现)
- 数的表示--任意进制的转换--大数
- 【笔记】【C语言】任意进制之间的转换(支持小数部分)
- 任意进制间的转换
- 笔试小题,将十进制转换为任意进制的数字。
- 十进制转换为任意进制及操作符重载
- 算法学习笔记12-任意进制数的转换
- 将10进制数转换成任意进制数
- Java的任意进制间转换
- 关于进制转换的一些函数(可以任意进制转换为任意进制)
- 十进制数转换成任意进制 (基础题) HLG 1937
- C语言将任意数转换成任意进制
- 数制转换--十进制转换任意进制---栈--初始化--调用--每日一练(七)
- shell命令实现任意进制之间的转换
- 面试热题——任意进制(32进制及以下)之间的转换
- 10进制向任意进制的转换
- c++十进制int型整数转换成计算机中存储的任意进制