PAT甲级——1019 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 ∑i=0k(aibi). Here, as usual, 0≤ai<b 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<N≤109 is the decimal number and 2≤b≤109 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
//General Palindromic Number
#include<stdio.h>
#include<vector>
using namespace std;
vector<int>V;
int main(void){
int n, b;
while (scanf("%d%d", &n, &b) != EOF){
V.clear();
if (n == 0){//如果是0的话,不论什么进制都是回文数字
puts("Yes");
printf("0\n");
continue;
}
while (n){//用V来存储b进制下的各个位数
V.push_back(n % b);
n /= b;
}
bool result = true;;
for (int i = 0; i < V.size(); i++){
if (V[i] != V[V.size() - i - 1]){
result = false;//一有不等的,就不是回文
break;
}
}
if (result){
puts("Yes");
}
else puts("No");
for (int i = V.size() - 1; i >= 0; i --){
if (i == V.size() - 1)printf("%d", V[i]);
else printf(" %d", V[i]);
}
printf("\n");
}
return 0;
}
PAT甲级——1019 General Palindromic Number的更多相关文章
- PAT 甲级 1019 General Palindromic Number(20)(测试点分析)
1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...
- PAT 甲级 1019 General Palindromic Number(简单题)
1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...
- PAT 甲级 1019 General Palindromic Number (进制转换,vector运用,一开始2个测试点没过)
1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards ...
- PAT 甲级 1019 General Palindromic Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be ...
- PAT Advanced 1019 General Palindromic Number (20 分)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT甲级——A1019 General Palindromic Number
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- PAT 1019 General Palindromic Number
1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards ...
- PAT 1019 General Palindromic Number[简单]
1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...
随机推荐
- Jlink线序问题
- CountUp.js 数字跳转效果小插件
CountUp.js 实现数字跳转效果的小插件 //调用方法 const easingFn = function (t, b, c, d) { var ts = (t /= d) * t; var ...
- IO读写
1.read & write read: 把数据从内核缓冲区复制到进程缓冲区. write: 把数据从进程缓冲区复制到内核缓冲区. 上层程序的IO操作.不是物理设备级别的读写,而是缓存的复制. ...
- 问:为什么java是单继承,但却是多实现的呢?
在学习的过程中,我发现了如题的这个有趣的问题. 单继承不必解释,一个类只能有一个直接父类:但是对于接口的实现,一个类却能够实现多个接口. 为什么是这种情况呢?我们来举个简单的栗子看一下: class ...
- openv uMat和Mat数据格式的转换
Mat 转成 UMat: UMat umat; mat.copyTo(umat); UMat转成 Mat : Mat mat; umat.copyTo(mat);
- vue整合外部js
vue引入外部jsimport { TrackLine } from "../../../../../static/js/trajectory.js";import { initM ...
- Channels(纪念一下卡我心态的一道题)
链接:https://ac.nowcoder.com/acm/contest/3947/C来源:牛客网 题目描述 Nancy喜欢学习,也喜欢看电视. 为了想了解她能看多长时间的节目,不妨假设节目从时刻 ...
- CodeForces 1287B Hyperset
N^2遍历所有得(i,j)然后可以根据(i,j)字符串构造出来第三个T字符串,然后查找一下是否有这个T存在即可,注意最后答案要/3因为会重复出现. #include <stdio.h> # ...
- ajax上传图片到服务器简单操作
前端: 通过Ajax方式上传文件,使用FormData进行Ajax请求.上传文件或图片时,要求的格式为enctype ="multipart/form-data"(以二进制格式上传 ...
- nouveau :failed to create kernel chanel,-22
一:錯誤描述:今天在重啓 Ubuntu 的過程中,出現下圖的 grub 選項,系統重啓/開機之後出現以下畫面,然後選擇 Ubuntu 之後黑屏,提示錯誤:nouveau :failed to crea ...