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++;
- }
- }
- }
-
相关阅读:
url找不到404的问题,url被拼接
dp转自动机:1017T4
什么蓝牙耳机适合运动、运动用的蓝牙耳机推荐
【slam十四讲第二版】【课后习题】【第九讲~后端2】
计算机竞赛 题目:基于深度学习的图像风格迁移 - [ 卷积神经网络 机器视觉 ]
盲水印接口,版权保护,防止篡改
如何使用PySide2将designer设计的ui文件加载到Python类上鼠标拖拽显示路径
iOS小技能:SKU视图搭建
(二)随机变量的数字特征:探索概率分布的关键指标
2 HTML
-
原文地址: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