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 (. Here, as usual, 0 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 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 "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
鸣谢网友“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的更多相关文章
- PAT 1019 General Palindromic Number[简单]
1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...
- 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(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 ...
- 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
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- 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 ...
- PAT 甲级 1019 General Palindromic Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be ...
随机推荐
- Linux中.rar文件解压
1. 下载: https://www.rarlab.com/download.htm 我下载的是RAR 5.61 for Linux x64 2. 安装: 解压:tar -zxvf rarlinux- ...
- Windows下使用命令安装Python的scipy库出错的解决
平时使用Python都是在Sublime下使用,不想使用IDE.使用各种库时安装也就是使用pip安装即可.来说说今天自己遇到的一个问题:使用scipy数学库时,使用命令: pip install sc ...
- File类文件的常见操作
boolean exists() 判断文件或者目录是否存在 boolean isFile() 判断是否是文件 boolean isDirectory() 判断是否是目录 String getPath ...
- git 修改默认编辑器
vim,notepad(windows自带),notepad++ 当然要选notepad++ 1.首先下载notepad++ 2.将notepad++安装目录放到path中 3.git config ...
- ZZNUOJ 2022 摩斯密码
map打表存一下对应的密码 不会map感觉不好弄这题 #include<stdio.h> #include<string.h> #include<math.h> ...
- 关于使用python.numpy的tips
产生含有5个数字的随机向量时,注意写法 import numpy as np A=np.random.randn(5,1) # 注意不要只写5 B=np.random.randn(5)与A不一样 ...
- MYSQL常用函数(聚合函数(常用于GROUP BY从句的SELECT查询中))
AVG(col)返回指定列的平均值 COUNT(col)返回指定列中非NULL值的个数 MIN(col)返回指定列的最小值 MAX(col)返回指定列的最大值 SUM(col)返回指定列的所有值之和 ...
- Oracle中判断(case when),截取(substr),位置(instr)用法
转自:http://rainbowdesert.iteye.com/blog/1677911 博客分类: SQL 1. 判断(case when) SELECT col1, col2, CASE ...
- Spring Boot 之注解@Component @ConfigurationProperties(prefix = "sms") 使用@ConfigurationProperties读取yml配置
从spring-boot开始,已经支持yml文件形式的配置,@ConfigurationProperties的大致作用就是通过它可以把properties或者yml配置直接转成对象 @Componen ...
- linux ----> centos 网络、tomcat、vi、等等的配置和使用
网络/配置 环境: centos6.8-mini-version virtualbox 工具: FileZilla client SecureCRT 静态ip地址 每一台计算机分配有一个固定的IP地 ...