pat1019. General Palindromic Number (20)
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 ai as the sum of (aibi) for i from 0 to k. Here, as usual, 0 <= ai < b 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 non-negative 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 non-negative numbers N and b, where 0 <= N <= 109 is the decimal number and 2 <= b <= 109 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
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,b;
scanf("%d %d",&n,&b);
vector<int> v;
v.push_back(n%b);//注意n==0的情况!!
n/=b;
while(n){
v.push_back(n%b);
n=n/b;
}
int i;
for(i=;i<v.size()/;i++){
if(v[i]!=v[v.size()--i]){
break;
}
}
if(i==v.size()/){
printf("Yes");
}
else{
printf("No");
}
printf("\n");
printf("%d",v[v.size()-]);
for(i=v.size()-;i>=;i--){
printf(" %d",v[i]);
}
printf("\n");
return ;
}
pat1019. General Palindromic Number (20)的更多相关文章
- PAT1019:General Palindromic Number
1019. General Palindromic Number (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- 1019 General Palindromic Number (20)(20 point(s))
problem A number that will be the same when it is written forwards or backwards is known as a Palind ...
- 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 ...
- PAT (Advanced Level) Practice 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 ...
- 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 ...
- 1019. General Palindromic Number (20)
生词以及在文中意思 forward 向前地 backward 向后地 palindromic 回文的 base 基数(如十进制的10 和二进制的2) numeral system 数制 decimal ...
- PAT (Advanced Level) 1019. General Palindromic Number (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲题题解-1019. General Palindromic Number (20)-又是水题一枚
n转化为b进制的格式,问你该格式是否为回文数字(即正着写和倒着写一样)输出Yes或者No并且输出该格式又是水题... #include <iostream> #include <cs ...
随机推荐
- 设置datalist指定行的背景色
前台: <div class="table-responsive" > <table class="table table-bordered table ...
- ubuntu - 安装软件问题
problem & solution 问题1 - E: 无法定位软件包 @原因(1) - 没有添加相应软件的镜像源(软件源) 解决方案 用 gedit/vi/vim - 在 /etc/a ...
- Kafka学习文档
本教程假定您是一只小白,没有Kafka 或ZooKeeper 方面的经验. Kafka脚本在Unix和Windows平台有所不同,在Windows平台,请使用 bin\windows\ 而不是bin/ ...
- [内容分享]粗略判断Shader每条代码的成本
https://mp.weixin.qq.com/s/Vyn1bKaBMHommxbnFPPQeg Unity对Shader文件进行编译的时候,DX9和DX11的版本会直接生成汇编码. ? len ...
- CF431B Shower Line
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibil ...
- Java基础笔记(十八)——多态
多态表示同一个操作作用在不同对象时,会有不同的结果. 多态可分为编译时多态和运行时多态. 编译时多态:方法重载,编译时就可以确定到底调用哪个方法,可以被看做一个类中的方法多态性. 运行时多态:只有在运 ...
- kindeditor使用记录
--------------------------资源 百度下载包 kindeditor-4.1.11-zh-CN 解压后根据需要选择asp / asp.net / jsp / php 文件夹之一 ...
- spring读取配置文件,且获取bean实例
import org.springframework.beans.factory.BeanFactory;import org.springframework.beans.factory.xml.Xm ...
- 实施MySQL ReplicationDriver支持读写分离
MySQL 提供支持读写分离的驱动类: com.mysql.jdbc.ReplicationDriver 替代 com.mysql.jdbc.Driver 注意,所有参数主从统一: jdbc:mysq ...
- STS(spring tool suite)修改默认编码
安装STS后首先要做的修改默认编码: 1.windows--perferences--general--workspace,Text file encoding设置成utf-8 2.windows-- ...