ZOJ Problem Set - 1078 Palindrom Numbers
来源:互联网 发布:淘宝全网数据分析工具 编辑:程序博客网 时间:2024/03/29 06:11
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代码:
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
int a[1000];
bool isp(int len)
{
int k=(len)/2;
for(int i=0;i<k;i++)
{
if(a[0+i]!=a[len-1-i])
return false;
}
return true;
}
int main()
{
int num;
while((cin>>num)&&num)
{
string re="";
for(int i=2;i<=16;i++)
{
int temp=num;
int len=0;
while(temp)
{
a[len++]=temp%i;
temp/=i;
}
if(isp(len))
{
re+=i;
}
}
if(re!="")
{
cout<<"Number "<<num<<" is palindrom in basis";
for(int i=0;i<re.length();i++)
{
cout<<" "<<(int)re[i];
}
cout<<endl;
}
else
{
cout<<"Number "<<num<<" is not a palindrom"<<endl;
}
}
}
- 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
- 把Eclipse中提示的API帮助信息设置成中文JavaDOC
- mini2440驱动分析之LCD
- lock in C#
- 配置jdk(classpath又忘了./;)
- JAVA-MyEclipse 自动提示(按alt+/)时假死现像
- ZOJ Problem Set - 1078 Palindrom Numbers
- 检查APK版本并更新
- 防手贱必备——python 自动关窗口
- 最大公约数和最小公倍数
- 最大公约数和最小公倍数(2)
- Git学习笔记
- Git常用命令
- 黑马程序员——01 流控语句
- 百度面试经历