PAT甲级——A1019 General Palindromic Number
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.
Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number N>0 in base b≥2, where it is written in standard notation with k+1 digits ai as (. Here, as usual, 0 for all i and ak is non-zero. Then N is palindromic if and only if ai=ak−i for all i. Zero is written 0 in any base and is also palindromic by definition.
Given any positive decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.
Input Specification:
Each input file contains one test case. Each case consists of two positive numbers N and b, where 0 is the decimal number and 2 is the base. The numbers are separated by a space.
Output Specification:
For each test case, first print in one line Yes
if N is a palindromic number in base b, or No
if not. Then in the next line, print N as the number in base b in the form "ak ak−1 ... a0". Notice that there must be no extra space at the end of output.
Sample Input 1:
27 2
Sample Output 1:
Yes
1 1 0 1 1
Sample Input 2:
121 5
Sample Output 2:
No
4 4 1
#include <iostream>
#include <vector>
using namespace std;
//此处11进制中的10就是10,而不是a
int main()
{
int N, b;
cin >> N >> b;
vector<int>v1, v2;
while (N)
{
v1.push_back(N%b);
N /= b;
}
v2.assign(v1.rbegin(), v1.rend());
if (v1 == v2)
cout << "Yes" << endl;
else
cout << "No" << endl;
if (v2.size() == )
cout << ;
else
{
cout << v2[];
for (int i = ; i < v2.size(); ++i)
cout << " " << v2[i];
}
cout << endl;
return ;
}
最新文章
- Apache 安装配置详情
- 【OpenJudge 1793】矩形覆盖
- js中的console很强大
- AFNetworking(AFN)总结
- Centos上Docker 使用dockerfile构建容器实现ssh
- .net获取select控件中的文本内容
- 【python】在python中调用mysql
- 上传至应用商店以及testflight相关。
- 修改linux文件/文件夹权限
- [转]oracle误删数据的恢复
- 妙味H5交互篇备忘
- Code Sign error: No code signing identities found: No valid signing identities
- centos7下编译安装mysql
- Java入门——(1)Java编程基础
- crm 数据展示 和分页思想(一)
- 金蝶K3 WISE BOM多级展开_销售成本表
- socket端口绑定后通过bat干掉
- 491. Increasing Subsequences
- STM32f103的数电采集电路的DMA设计和使用优化程序
- Kindle2018 一周使用报告