ZOJ Problem Set - 1078 Palindrom Numbers
来源:互联网 发布:淘宝运营专才 试题 编辑:程序博客网 时间:2023/06/07 05:48
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
Source: South America 2001
#include<cstdio>
#include<cstring>
using namespace std;
char a[20];
bool b[18];
int main()
{
int n,i,j,k;
while(scanf("%d",&n)&&n)
{
for(i=2;i<=16;i++)
b[i]=false;
for(i=2;i<=16;i++)//2~16进制
{
int m=n;
int j=0;
while(m)
{
a[++j]=m%i;
m/=i;
}
for(k=1;k<=j/2;k++)//判断是不是回文串
{
if(a[k]!=a[j-k+1])
break;
}
if(k>j/2)
b[i]=true;
}
for(i=2;i<=16;i++)
if(b[i]) break;
if(i>16)
printf("Number %d is not a palindrom\n",n);
else
{
printf("Number %d is palindrom in basis",n);
for(i=2;i<=16;i++)
if(b[i])
printf(" %d",i);
printf("\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
- oracle新建数据库
- poj 1008 Maya Calendar
- JAVA中的List的使用
- MFC小程序 简易网络聊天室 VS2012 ODBC连接MySql数据库和网络Socket通信
- ibaties自增
- ZOJ Problem Set - 1078 Palindrom Numbers
- 有关协议的用法
- linux内核--段页式管理内存的方法
- 比较 SLF4J 与 log4j
- c++程序设计原理与实践--读书笔记
- 类似天猫那样的侧边导航栏的快速实现
- 【Android API】java.util.List<E>
- 就地交换两个数
- mysql获取汉字拼音