第二层第五题:双基回文数
来源:互联网 发布:淘宝客服骗局 编辑:程序博客网 时间:2024/04/30 13:32
Dual Palindromes
Mario Cruz (Colombia) & Hugo Rickeboer (Argentina)
A number that reads the same from right to left as when read from left toright is called a palindrome. The number 12321 is a palindrome; the number77778 is not. Of course, palindromes have neither leading nor trailing zeroes,so 0220 is not a palindrome.
The number 21 (base 10) is not palindrome in base 10, but the number 21(base 10) is, in fact, a palindrome in base 2 (10101).
Write a program that reads two numbers (expressed in base 10):
- N (1 <= N <= 15)
- S (0 < S < 10000)
and then finds and prints (in base 10) the first Nnumbers strictly greater than S that are palindromic when written in two ormore number bases (2 <= base <= 10).
Solutions to this problem do not require manipulating integers larger thanthe standard 32 bits.
PROGRAM NAME: dualpal
INPUT FORMAT
A single line with space separated integers N and S.
SAMPLE INPUT (file dualpal.in)
3 25
OUTPUT FORMAT
N lines, each with a base 10 number that is palindromicwhen expressed in at least two of the bases 2..10. The numbers should be listedin order from smallest to largest.
SAMPLE OUTPUT (file dualpal.out)
26
27
28
题目大意:如果一个数字在两个或更多进制下(2≤进制数≤10)均为回文数,则称该数为双基回文数。题目给出两个数字:S(0<S<10000)和N(1≤N≤15),求出大于S的连续N个双基回文数。
枚举数字,然后枚举进制,然后转换进制,然后判断,然后输出,然后。。。AC
代码如下:
/*ID:su1q2d2LANG:C++TASK:dualpal*/#include<iostream>#include<cstring>#include<cstdio>#define maxl 50#define lint long longusing namespace std;void cn(char ans[],int x,int b){int i=0;while(x>0){ans[i]=x%b+'0';x/=b;i++;}ans[i]='\0';return ;}bool pal(char x[]){int n;int i;n=strlen(x);for(i=0;i<n;i++){if(x[n-i-1]!=x[i]) return false;}return true;}int main(){freopen("dualpal.in","r",stdin);freopen("dualpal.out","w",stdout);int i;int j;int c;int s;int n;int is;char afc[maxl];scanf("%d",&n);scanf("%d",&s);c=0;for(i=s+1;c<n;i++){is=0;for(j=2;j<=10;j++){cn(afc,i,j);if(pal(afc)) is++;if(is>=2) break;}if(is>=2){printf("%d\n",i);c++;}}return 0;}
- 第二层第五题:双基回文数
- 第二层第四题:回文平方数
- 双基回文数
- 双基回文数
- 双基回文数
- 双基回文数
- 双基回文数!!!
- 双基回文数
- 双基回文数
- 双基回文数
- 双基回文数
- 双基回文数
- 最小双基回文数
- 171220-回文数【连续第五十六天】
- 第二周Palindrome Number回文数
- 第二章第五题
- 第二章第五题
- 第五章第二题
- codeforces #323 c GCD Table(map)
- 玩转Google开源C++单元测试框架Google Test系列(gtest)
- adb命令
- iOS编程------集合视图UICollectionView
- UVa 455 - Periodic Strings【字符串】
- 第二层第五题:双基回文数
- 树状数组模板
- 细说结构字节对齐
- QT5 学习之路24---Qt 绘制系统简介
- tcp要点学习-断开连接
- UVALive 7146 muliset<> 容器用法 防御塔
- 惯性导航之欧拉角与万向节死锁(三)
- Bootstrap CSS——按钮式下拉菜单
- Npoi导出word(Peanuts)