ZOJ Problem Set - 1078||Palindrom Numbers
来源:互联网 发布:中国网络为什么要设墙 编辑:程序博客网 时间:2024/04/27 10:46
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
一次AC过~~求n在2到16进制中,哪个进制数是回文数就输出那个数。
#include <iostream>#include <stdio.h>using namespace std;int d(int *a, int n){int i,j;for (i = 0, j = n - 1; i < n / 2; i++)if (a[i] != a[j--])break;if (i == n / 2)return 1;return 0;}int p(int x,int n){int i=0;int a[50];while (x){a[i++] = x % n;x = x / n;}return d(a, i);}int main(){int n,i,a[202],j;while (cin >> n && n){j = 0;for (i = 2; i <= 16; i++)if (p(n, i)){a[j++] = i;}if (j){printf("Number %d is palindrom in basis", n);for (i = 0; i < j; i++)printf(" %d", a[i]);printf("\n");}elseprintf("Number %d is not a palindrom\n",n);}return 0;}
- ZOJ Problem Set - 1078(Palindrom Numbers)
- ZOJ Problem Set - 1078 Palindrom Numbers
- ZOJ Problem Set - 1078||Palindrom Numbers
- ZOJ Problem Set - 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--1078:Palindrom Numbers
- ZOJ 1078 Palindrom Numbers
- 1078 Palindrom Numbers
- ZOJ Problem Set - 1383 Binary Numbers
- ZOJ Problem Set - 1383 Binary Numbers
- ZOJ Problem Set - 2001 Adding Reversed Numbers
- ZOJ Problem Set - 1383 Binary Numbers
- ZOJ Problem Set - 2001 Adding Reversed Numbers
- How to write a DCOM server in C# 如何用C#编写DCOM服务器
- HDOJ:Text Reverse
- log4cxx 使用代码进行配置
- 加载web项目的路径的方法
- spring+websocket整合使用
- ZOJ Problem Set - 1078||Palindrom Numbers
- CommonWidget
- CDHtmlDialog的基本使用
- js parseURL
- eclipse中could not find symbol "XXX" in index
- Locate
- MySQL性能优化的21个最佳实践 和 mysql使用索引
- Page
- python 多线程 start_new_thread()