1019 General Palindromic Number (20 分)
 

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 a​i​​ as (. Here, as usual, 0 for all i and a​k​​ is non-zero. Then N is palindromic if and only if a​i​​=a​k−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 "a​k​​ a​k−1​​ ... a​0​​". 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

鸣谢网友“CCPC拿不到牌不改名”修正数据!

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxnum 100005 int main(){
int a,b;
scanf("%d%d",&a,&b);
vector<int> vec;
while(a){
vec.push_back(a%b);
a /= b;
}
// for(auto num:vec)cout << num << " "; int flag = ;
for(int i=;i < vec.size()/+;i++){
if(vec[i] != vec[vec.size()-i-])flag = ;
}
if(flag)cout << "Yes" << endl;
else cout << "No" << endl; for(int i=vec.size()-;i >= ;i--){
cout << vec[i];
if(i!=)cout << " ";
}
return ;
}

PAT 1019 General Palindromic Number的更多相关文章

  1. PAT 1019 General Palindromic Number[简单]

    1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...

  2. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  3. PAT 甲级 1019 General Palindromic Number(20)(测试点分析)

    1019 General Palindromic Number(20 分) A number that will be the same when it is written forwards or ...

  4. PAT 甲级 1019 General Palindromic Number(简单题)

    1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...

  5. PAT 甲级 1019 General Palindromic Number (进制转换,vector运用,一开始2个测试点没过)

    1019 General Palindromic Number (20 分)   A number that will be the same when it is written forwards ...

  6. 1019 General Palindromic Number (20 分)

    1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards or ...

  7. PAT甲级——1019 General Palindromic Number

    A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...

  8. PTA (Advanced Level) 1019 General Palindromic Number

    General Palindromic Number A number that will be the same when it is written forwards or backwards i ...

  9. PAT 甲级 1019 General Palindromic Number

    https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be ...

随机推荐

  1. JavaScript运行机制详解

    JavaScript运行机制详解   var test = function(){ alert("test"); } var test2 = function(){ alert(& ...

  2. layout_gravity与gravity的区别,和padding margin的区别

    https://blog.csdn.net/github_39688629/article/details/77790541

  3. go 内嵌对象类型

    demo1 // Sample program to show how to embed a type into another type and // the relationship betwee ...

  4. git 修改默认编辑器

    vim,notepad(windows自带),notepad++ 当然要选notepad++ 1.首先下载notepad++ 2.将notepad++安装目录放到path中 3.git config ...

  5. docker下debian镜像开启ssh, 允许root用密码登录

    用的官方python镜像做开发, 暴露端口, 用pycharm ssh进去开发. 忽然发现本来ssh能连上, 但是更了新的python镜像连不上了. 有折腾了一下, 连上了. 主要是python官网镜 ...

  6. 多线程工具之CompletionService

    这里涉及到Java的多线程并发知识,以及线程池相关的知识.就不在此说明了.具体说说CompletionService的应用场景和使用方法. 比如我们有10个线程需要丢到线程池里面去执行,然后把10个线 ...

  7. js插件---iCheck是用来做什么的

    js插件---iCheck是用来做什么的 一.总结 一句话总结:25 种参数 用来定制复选框(checkbox)和单选按钮(radio button) 定制复选框 定制单选按钮 1.iCheck常用的 ...

  8. (9)进程---JoinableQueue队列

    消费者模型-->存和取得过程 和Queue队列区别:解决了Queue队列拿取完,程序阻塞不能自动关闭(依靠放入None来解决)的问题--->参见上个例子 put 存入, get 获取 q. ...

  9. 书法字帖 PDF转化为可打印PDF

    书法类的PDF,因为底色是黑色的,打印起来特别费墨,所以需要转化成白底黑字的文件, 才好打印. 1)用 pdfbox 的 ExtractImages 命令,抽出所有的图片 https://pdfbox ...

  10. RHEL 5 , 用安装CD作为YUM的Repository

    官方文档写的非常好 14.5. Upgrading the System Off-line with ISO and Yum Create a target directory to mount yo ...