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. java实现网络请求超时自动熔断

    原文:https://www.jianshu.com/p/326465500d1c?utm_campaign 使用场景 之前在实现熔断降级组件时,需要实现一个接口的超时中断,意思是,业务在使用熔断降级 ...

  2. 如果将 macOS Mojave 降级为 macOS Sierra 或者更低版本

    当前系统是10.14,我想装回10.11 办法: 1. 下载10.11, 我是从themacgo网站下载的 https://themacgo.com/macos-sierra-10-12-1-dmg- ...

  3. 1113 form表单与css选择器

    目录 1.form表单 form元素 特点 参数 form元素内的控件 1.input的使用 2.select标签 3.textarea元素 4.autofocus属性 2.CSS 1.基础语法 cs ...

  4. MATLAB中.m文件生成.dll

    1.配置编译环境 在命令行窗口输入: mbuild -setup 如果出现以下提示信息说明成功: 如果提示信息为: 错误使用mbuild(line 164) Unable to complete su ...

  5. Ubuntu 搭建 Ftp 服务器

    1.在 ubuntu 中 下载 vsftpd  要是你安装了 vsftpd  输入:vsftpd -v ,会有版本提示 如果没有,则进行安装 vsftpd 输入  apt-get install vs ...

  6. 从运行时的工作空间获取EMF文件(IFILE)

    //EMFFILE_URI为EMF文件的URI String uriString = EMFFILE_URI.trimFragment().toPlatformString(true); if (ur ...

  7. adb连接各模拟器端口

    天天模拟器 adb connect 127.0.0.1:6555 网易MuMu adb connect 127.0.0.1:5555

  8. 题解 [APIO2014]连珠线

    题解 [APIO2014]连珠线 题面 解析 首先这连成的是一棵树啊. 并且\(yy\)一下,如果钦定一个根, 那么这上面的蓝线都是爸爸->儿子->孙子这样的,因为像下图这样的构造不出来: ...

  9. Shell 02 数据运算/条件测试

    一.整数运算工具 1.使用expr命令(运算两边必须有空格,引用变量时必须加$符号) [root@svr5 ~]# x=10    //定义变量x expr $x + 10      20       ...

  10. SpingMVC入门

    Springmvc简介及配置 1. 什么是springMVC? Spring Web MVC是一种基于Java的实现了MVC设计模式的.请求驱动类型的.轻量级Web框架. 2. SpringMVC处理 ...