Palindrom Numbers
来源:互联网 发布:软件项目开发阶段 编辑:程序博客网 时间:2024/04/27 22:28
题目描述
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.
输入
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.
输出
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.
样例输入
17
19
0
样例输出
Number 17 is palindrom in basis 2 4 16
Number 19 is not a palindrom
提示
题目大意就是给你一个数找你计算从2-16进制的回文数进制。
AC代码
//#include <bits/stdc++.h>#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <stack>#include <set>#include <queue>#include <algorithm>#define CLR(a, b) memset(a, (b), sizeof(a))#define INF 0x3f3f3f3f#define eps 1e-8typedef long long LL;using namespace std;int save[17];int te[20];int main(){#ifdef LOCAL freopen("E://in.txt","r",stdin);#endif // LOCAL int n; while(scanf("%d",&n)&&n) { CLR(save,0); for(int i=2; i<=16; ++i) { int a=n,k=0; CLR(te,0); while(a) { te[k]=a%i; a/=i; k++; } int flag=0; for(int j=0; j<k; j++) { if(te[j]!=te[k-1-j]) { flag=1; break; } } if(flag==0) { ++save[i]; } } int cnt=0; for(int j=2; j<=16; j++) { if(save[j]) { cnt++; break; } } if(cnt==0) printf("Number %d is not a palindrom\n",n); else { printf("Number %d is palindrom in basis",n); for(int j=2; j<=16; j++) { if(save[j]) printf(" %d",j); } printf("\n"); } } return 0;}
- 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
- ZOJ--1078:Palindrom Numbers
- UI_tableView
- WebSocket 初探
- Android 切换日夜间模式
- oc中在控件上显示图片
- 论文笔记:Clustering is efficient for approximate maximum inner product search
- Palindrom Numbers
- UI组件之GridView实现图片浏览器
- 0.0与0.0f区别
- nova-compute Periodic tasks 机制
- 学习sqlite3(四)---SQLite中的高级SQL
- 机器人操作系统ROS教程(二) ROS总体框架
- 身份证的正则表达式
- Java源码解析 Iterator<E>
- 通过bower 下载管理angularjs