当前位置:网站首页>PAT Class A 1019 Common Palindrome Numbers
PAT Class A 1019 Common Palindrome Numbers
2022-08-02 17:02:00 【keyboard sonata】
A number is a palindrome if it reads exactly the same from front to back as it does from back to front.
For example, 1234321 is a palindrome.
All one-digit numbers are palindromes.
We generally consider palindrome in decimal, but the concept of palindrome can also be applied to numbers in other bases.
An integer N has k+1 bits in base b, and the i-th digit is ai, (0≤i≤k), then N=∑ki=0(aibi).
In general, 0≤ai
If ai=ak−i is satisfied for any i, then N is a palindrome in base b.
0 is represented as 0 in any base, and is considered a palindrome.
Now given an integer N, please judge whether it is a palindrome in the base b representation.
Input format
A line containing two integers N and b.Output format
The output consists of two lines.If N is a palindrome in base b, the first line outputs Yes, otherwise it outputs No.
The second line, output the representation of N in base b, including k+1 integers, and it is required to output ak,ak−1,…,a0 in order, and the integers are separated by spaces.
Data Range
0≤N≤109,
2≤b≤109
Input Example 1:
27 2
Output Sample 1:
Yes
1 1 0 1 1
Input Sample 2:
121 5
Example output 2:
No
4 4 1
My solution:
#include using namespace std;const int N = 1e9 + 10;int n, b;vector nums;bool check(){for(int i = 0, j = nums.size() - 1; i < j; i ++, j --){if(nums[i] != nums[j]){return false;}}return true;}int main(){cin >> n >> b;if(!n) nums.push_back(0);while(n) nums.push_back(n%b), n/=b;if(check()) puts("Yes");else puts("No");cout << nums.back();for(int i = nums.size() - 2; i >= 0; i -- ) cout << " " << nums[i];return 0;} 边栏推荐
猜你喜欢

Redis + Caffeine实现多级缓存

职工管理系统(SSM整合)
![解决(An error happened during template parsing (template: “class path resource [templates/...]](/img/d9/df0027ed6063a27f6be117b9d67a06.png)
解决(An error happened during template parsing (template: “class path resource [templates/...]

【故障诊断】基于PSO_VMD_MCKD方法的风机轴承微弱故障诊断
![[Fault Diagnosis] Weak Fault Diagnosis of Fan Bearing Based on PSO_VMD_MCKD Method](/img/43/719caffc79950edd18719ad0ba3aff.jpg)
[Fault Diagnosis] Weak Fault Diagnosis of Fan Bearing Based on PSO_VMD_MCKD Method

如何查看微信小程序服务器域名并且修改

基于ip的证书

常见(MySQL)面试题(含答案)

FIR滤波器设计之窗函数法

初入c语言
随机推荐
EL 表达式 & JSTL 标签库
ELK日志分析系统
2022/7/15,我的人生中第一篇博客,不忘初心,砥砺前行!
什么是Nacos?
C语言的基本程序结构详细讲解
【JS执行机制】
2021 annual summary - complete a year of harvest
JSP技术
PAT甲级 1145 哈希 - 平均查找时间
阅读,是最便宜的高贵
ADB常用命令--测试人员必备
2021 Huawei Cup Mathematical Modeling Contest E question - Ultra-Wideband (UWB) precise positioning problem under signal interference
双亲委派机制
什么是hashCode?
nodemon : 无法加载文件 D:\Program Files\nodejs\node_global\nodemon.ps1
Redis最新6.27安装配置笔记及安装和常用命令快速上手复习指南
为什么四个字节的float表示的范围比八个字节的long要广?
如何查看微信小程序服务器域名并且修改
【无标题】
Servlet 技术1