PAT 1019 General Palindromic Number

时间:2022-09-06 23:56:25
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&lbrack;简单&rsqb;

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

  2. PAT &lpar;Advanced Level&rpar; Practice 1019 General Palindromic Number &lpar;20 分&rpar; 凌宸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 &lpar;进制转换,vector运用,一开始2个测试点没过&rpar;

    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 &lpar;Advanced Level&rpar; 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. UVA 1151 买还是建&lpar;最小生成树&rpar;

    买还是建 紫书P358 [题目链接]买还是建 [题目类型]最小生成树 &题解: 这题真的心累,看了3天,最后照着码还是wa,先放lrj代码,以后再看吧 &代码: // UVa1151 ...

  2. 【WebMisCentral WMC】基于Extjs 4&period;2x的企业级用户授权认证中心系统&lpar;SSO&plus;AM&plus;SM&rpar;&comma;多租户SAAS应用

    http://saas.chinacloudtech.com 题记 三年磨一剑,在企业信息化的道路上已经走了3年之久了,3年多时间里做了很多,突破了很多:有无奈和辛酸,也有收货与喜悦:自我价值也在不断 ...

  3. 802&period;11(wifi)的MAC层功能

    MAC层是802.11的主要功能部分.上层应用通过调用MAC层提供的接口原语调用MAC层的功能. MAC一共向上提供了2大类接口原语,共30种.数据(1)和管理(29).数据部分就是提供普通数据包的收 ...

  4. Lake Counting &lpar;DFS&rpar;

    N*M的园子,雨后积起了水.八连通的积水背认为是连接在一起的.请求出园子里总共有多少水洼? dfs(Depth-First  Search)  八个方向的简单搜索.... 深度优先搜索从最开始的状态出 ...

  5. Winfrom 提示消息框公共类

    1.Winfrom项目经常会使用到消息提示,一般都使用MessageBox.Show方法,但是像错误提示,询问提示,警告提示写起来就有点复杂了,并且后面几种提示都带有图标,但是MessageBox.S ...

  6. MPSOC之4——petalinux提取源码

    petalinux使用太不方便,捆绑的太死板,也不通用,还不如直接用编译器来的简单高效. 本文说明从petalinux中提取出源代码的过程,前提是已经petalinux-build完成. 1. ubo ...

  7. Visual Studio 20周年,我和VS不得不说的故事

    Visual Studio 2017正式版已如期发布(点击这里查看发布全记录)!自去年 11 月正式宣布 Visual Studio 项目之后,微软终于正式推出了“宇宙最强集成开发环境(IDE)”的最 ...

  8. C&num; 格式化新招

    C# 格式化新招 ) from Attribute_Item where AttributeSysNo=$AttributeSysNo and Name='$Name' and SysNo !=$Sy ...

  9. linux中WDCP的日志彻底删除技巧

    apache或nginx都有开关默认日志,一个是正常访问日志,一个是错误的日志,目录在 /www/wdlinux/nginx-1.0.15/logs /www/wdlinux/httpd-2.2.22 ...

  10. NOI 16 买房子

    买房子(NOI 16) 总时间限制: 1000ms 内存限制: 65536kB 描述 某程序员开始工作,年薪N万,他希望在中关村公馆买一套60平米的房子,现在价格是200万,假设房子价格以每年百分之K ...