A number that reads the same from right to left as when read from left to right is called a palindrome.
和上期一样。回文数呢,就是从左到右从右到左读数都一样的数字。
The number 12321 is a palindrome; the number 77778 is not.
比如12321反过来读还是12321(所以是回文数),但77778就不是。
Of course, palindromes have neither leading nor trailing zeroes, so 0220 is not a palindrome.
但是0在首位或者个位都不算,所以0220不是一个回文数。
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).
给一个10进制数下的21,他不是一个回文数。但是2进制下的21(10101)就是一个回文数。
Write a program that reads two numbers (expressed in base 10):
写一个读入两个十进制数的程序,
and then finds and prints (in base 10) the first N numbers strictly greater than S that are palindromic when written in two or more number bases (2 <= base <= 10).
Solutions to this problem do not require manipulating integers larger than the standard 32 bits.
A single line with space separated integers N and S.
3 25
N lines, each with a base 10 number that is palindromic when expressed in at least two of the bases 2..10. The numbers should be listed in order from smallest to largest.
一共N航,每一行包含一个10进制数,至少两个进制们需要从小到大打印出来。
26 27 28
- /*
- ID: choiyin1
- PROG: dualpal
- LANG: C++
- */
- #include
-
- using namespace std;
- char leter[20]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J'};
- void changetheBase(int x,int base,char out[60])
- {
- stack<char> S;
- int i=0;
- while(x>0)
- {
- S.push(leter[x%base]);
- x/=base;
- }
- for(i=0;!S.empty();i++)
- {
- out[i]=S.top();
- S.pop();
- }
- out[i]=0;
- }
- bool isPalindromic(char input[60])
- {
- int temp[60];
- int len=strlen(input);
- for(int i=0;i
- {
- temp[len-i-1]=input[i];
- }
- for(int i=0;i
- {
- if(input[i]!=temp[i])
- return false;
- }
- return true;
- }
- bool islegal(int x)
- {
- char out[60];
- int ans=0;
-
- for(int i=2;i<=10;i++)
- {
- changetheBase(x,i,out);
- if(isPalindromic(out))
- {
- ans++;
- }
- if(ans>=2)
- return true;
- }
- return false;
- }
- int main()
- {
- int N,S,ans;
- freopen("dualpal.in","r",stdin);
- freopen("dualpal.out","w",stdout);
- scanf("%d%d",&N,&S);
- ans=0;
- for(int i=S+1;ans
- {
- if(islegal(i))
- {
- cout<
- ans++;
- }
- }
- }
-
相关阅读:
Git 常用命令
16进制的图片信息如何上传到FastDFS
2019史上最全java面试题题库大全800题含答案
PostgreSQL文本搜索(二)——表和索引
提升 Windows 生产力的实用工具集:Microsoft PowerToys | 开源日报 No.42
技术分享 | TiUP工具 - TiDB集群滚动升级核心流程解析
温习JAVA
Java2EE基础练习_chapter02流程控制
Spring 6【p命名空间和c命名空间】(五)-全面详解(学习总结---从入门到深化)
【Redis】Redis 数据结构介绍
-
原文地址:https://blog.csdn.net/GeekAlice/article/details/126928139