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++;
- }
- }
- }
-
相关阅读:
Java集合-ArrayList源码分析
飞桨(PaddlePaddle)数据加载教程
ESP32外部中断原理详解及代码示例
并查集知识梳理
vue3源码分析——手写diff算法
信息系统项目管理师0067:数据建模(5信息系统工程—5.2数据工程—5.2.1数据建模)
split和join方法用于字符串和数组的转换
JS-回到顶部
【MindSpore】CPU可以正常运行的,但是GPU下报错
Transformers基本组件(一)快速入门Pipeline、Tokenizer、Model
-
原文地址:https://blog.csdn.net/GeekAlice/article/details/126928139
-
最新文章
-
沪漂五周年了:我越来越迷茫了
Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
MySQL-Seconds_behind_master的精度误差
[MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
Agent OS :五种驯服不确定性的范式
PortSwigger SQL注入LAB11
数据库即时编译JIT
[Begin]AI Learn Data Day 0
深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU