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

解题思路
  题目大意:给定一个N和b,求N在b进制下,是否是一个回文数(Palindromic number)。其中,0<N,b<=10^9。
  使用int作为基本类型就足够了,然后进行进制转换,需要注意的是,b进制比较大,可能得到的不是一个单位数,比如16进制下的10~15。可以用char进行存储,然后比较。或者用一个的二维数组进行比较也行。

但是后来发现用char,数字+'0'可能会超出ascii表示的范围,有一个测试点就是过不去。

最终选择用vector<int>,很方便。

典型测试样例:

Yes
   
No
 

AC代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
int d,b;
cin>>d>>b;
char s[];
int k=;
while(d>){
s[k++]=d%b+'';
//cout<<d%b<<endl;
d=d/b;
}
k--;
//cout<<d<<endl;
int middle=int((+k)/);
int f=;
for(int i=;i<=middle;i++){
if(s[i]!=s[k+-i]){
f=;
break;
}
}
if(f){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
for(int i=k;i>=;i--){
cout<<s[i]-'';//可能b的进制比较大,所以要-'0'输出
if(i!=){
cout<<" ";
}
}
return ;
}
 

PAT 甲级 1019 General Palindromic Number (进制转换,vector运用,一开始2个测试点没过)的更多相关文章

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

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

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

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

  3. 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 ...

  4. PAT 甲级 1019 General Palindromic Number

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

  5. 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 ...

  6. General Palindromic Number (进制)

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

  7. 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 ...

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

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

  9. PAT 1019 General Palindromic Number[简单]

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

随机推荐

  1. C语言判断一个32位的数据,有多少位是1,然后用串口发送出来

    今天遇到了一个问题,遇到一个32位的数据,写一个子函数来判断它的多少位是1.我的思路一开始是把这个数据变成一个32位容量的数组然后每个位去比较是不是1,如果是1,就用另一个变量加1.最后返回这个变量. ...

  2. python-----多线程笔记

    多进程笔记: 多线程介绍: 多线程是为了同步完成多项任务,通过提高资源使用效率来提高系统的效率.线程是在同一时间需要完成多项任务的时候实现的. 最简单的比喻多线程就像火车的每一节车厢,而进程则是火车. ...

  3. BCB 中 Application->CreateForm 和 New 的一个区别

    Application->Create 和 NEW 的一个区别 最近写windows服务的时候,恰巧碰到一个问题.我建立了一个DataModal,然后在Datamodal的OnCreate 事件 ...

  4. C# GridView 的使用

    1.GridView无代码分页排序: 1.AllowSorting设为True,aspx代码中是AllowSorting="True":2.默认1页10条,如果要修改每页条数,修改 ...

  5. Apache正向代理与反向代理配置

    正向代理示例配置:ProxyRequests OnProxyVia On <Proxy *>Order deny,allowDeny from allAllow from 192.168. ...

  6. P4136 谁能赢呢? 脑子

    思路:脑子(教练说是博弈论?) 提交:1次 题解: 结论:若\(n\)为奇数后手胜,若\(n\)为偶数先手胜. 大致证明: 我们发现,若我们把棋盘黑白染色并设左上角为黑色,那么显然有:若\(n\)为奇 ...

  7. MySQL percona-toolkit工具详解

    一.检查和安装与Perl相关的模块 PT工具是使用Perl语言编写和执行的,所以需要系统中有Perl环境. 依赖包检查命令为: rpm -qa perl-DBI perl-DBD-MySQL perl ...

  8. locale与C字符编码

    ref: https://www.cnblogs.com/gatsby123/p/11150472.html Unicode 字符集 代码点 与编码表中的某个字符对应的代码值.在Unicode标准中, ...

  9. Java集合总结(一):列表和队列

    java中的具体容器类都不是从头构建的,他们都继承了一些抽象容器类.这些抽象容器类,提供了容器接口的部分实现,方便具体容器类在抽象类的基础上做具体实现.容器类和接口的关系架构图如下: 虚线框表示接口, ...

  10. iptables防火墙--------基本概念

    iptables按照规则进行处理,而iptables的规则存储在内核空间的信息包过滤表中,这些规则分别指定了源地址.目的地址.传输协议(TCP.UDP.ICMP)和服务类型(如HTTP.FTP和SMT ...