zoj 1078 Palindrom Numbers
来源:互联网 发布:淘宝商城外包 编辑:程序博客网 时间:2024/04/26 12:32
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
题意:给你一个十进制数,求他的2-16进制,判断是否为回文
#include <iostream>#include <cstring>#include <cstdio>int a[50000],b[50000],c[50000];using namespace std;int is_p(int n){ int flag=1; for(int i=n,j=0;i>=0;i--,j++) { b[j]=a[i]; // cout<<b[j]<<" "; } //cout<<endl; for(int i=0;i<n;i++) { if(a[i]!=b[i]) { flag=0; } } return flag;}int f(int n,int m){ memset(a,sizeof(a),0); memset(b,sizeof(b),0); int d; for(int i=0;n!=0;i++) { a[i]=n%m; n=n/m; d=i; // cout<<a[i]<<" "; } // cout<<endl; if(is_p(d)) return 1; return 0;}int main(){ int n; while(cin>>n) { if(n==0) break; memset(c,sizeof(c),0); int flag=0,k=0; for(int i=2;i<=16;i++) { //cout<<i<<endl; if(f(n,i)) { flag=1; c[k++]=i; } } if(!flag) printf("Number %d is not a palindrom\n",n); else { printf("Number %d is palindrom in basis",n); for(int i=0;i<k;i++) cout<<" "<<c[i]; cout<<endl; } } return 0;}
- ZOJ 1078 Palindrom Numbers
- zoj 1078 Palindrom Numbers
- ZOJ 1078 :Palindrom Numbers
- zoj 1078 Palindrom Numbers
- ZOJ 1078-Palindrom Numbers
- zoj 1078 Palindrom Numbers
- ZOJ--1078:Palindrom Numbers
- ZOJ Problem Set - 1078(Palindrom Numbers)
- ZOJ 1078 Palindrom Numbers
- ZOJ Problem Set - 1078 Palindrom Numbers
- ZOJ Problem Set - 1078||Palindrom Numbers
- ZOJ Problem Set - 1078 Palindrom Numbers
- 1078 Palindrom Numbers
- Palindrom Numbers
- Palindrom Numbers
- Palindrom Numbers
- zoj1078 Palindrom Numbers
- fjnu 1827 Palindrom Numbers
- mysql 插入中文乱码
- js什么是变量
- java中不太常见的东西(5)
- The equation
- 冒泡排序法
- zoj 1078 Palindrom Numbers
- Clob类型与String类型的相互转换
- Java中出现No enclosing instance of type XXX is accessible问题
- OpenCV——读取Mat对象的元素
- 只保留armeabi的.so文件用来减小apk包(不保证100%不崩溃)
- 函数(JavaScript)
- Mysql MDBS执行SELECT 顺序
- 一些小命令
- 尺取法。。