Palindrom Numbers 任意进制数转换
来源:互联网 发布:阿里云华南a和华南b 编辑:程序博客网 时间:2024/06/05 18:53
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;elsecout<<" ";}}} return 0; }
- Palindrom Numbers 任意进制数转换
- Palindrom Numbers
- Palindrom Numbers
- Palindrom Numbers
- zoj1078 Palindrom Numbers
- 1078 Palindrom Numbers
- fjnu 1827 Palindrom Numbers
- ZOJ1078 Palindrom Numbers
- ZOJ 1078 Palindrom Numbers
- zoj 1078 Palindrom Numbers
- zoj1078-Palindrom Numbers
- ZOJ 1078 :Palindrom Numbers
- zoj 1078 Palindrom Numbers
- ZJU1078-Palindrom Numbers
- ZOJ1078-Palindrom Numbers
- ZOJ 1078-Palindrom Numbers
- UVALive2389 ZOJ1078 Palindrom Numbers
- zoj 1078 Palindrom Numbers
- Linux下安装Oracle........
- 手机支付宝面临的风险和应对(III)---手机支付宝能照搬PC的思路吗?
- Android入门第十六篇之Style与Theme
- C++属性注册机制
- 时间控件资源分享
- Palindrom Numbers 任意进制数转换
- Java接收Flash请求的二进制流图片
- Ubuntu Terminal 安装chrome
- SVN 离线安装
- HBase-0.94.12部署文档
- c#.net excel文件导入到数据库 之一
- 编程乐趣:如何使用IE9捕获网页请求
- java抓取数据+破解屏蔽ip访问【多线程数据采集之三】
- C语言指针小解