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 ∑i=0k(aibi). 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 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<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
//General Palindromic Number
#include<stdio.h>
#include<vector>
using namespace std;
vector<int>V;
int main(void){
int n, b;
while (scanf("%d%d", &n, &b) != EOF){
V.clear();
if (n == 0){//如果是0的话,不论什么进制都是回文数字
puts("Yes");
printf("0\n");
continue;
}
while (n){//用V来存储b进制下的各个位数
V.push_back(n % b);
n /= b;
}
bool result = true;;
for (int i = 0; i < V.size(); i++){
if (V[i] != V[V.size() - i - 1]){
result = false;//一有不等的,就不是回文
break;
}
}
if (result){
puts("Yes");
}
else puts("No");
for (int i = V.size() - 1; i >= 0; i --){
if (i == V.size() - 1)printf("%d", V[i]);
else printf(" %d", V[i]);
}
printf("\n");
}
return 0;
}
PAT甲级——1019 General Palindromic Number的更多相关文章
- 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 ...
- PAT 甲级 1019 General Palindromic Number
https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 A number that will be ...
- 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甲级——A1019 General Palindromic Number
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 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- PAT 1019 General Palindromic Number
1019 General Palindromic Number (20 分) A number that will be the same when it is written forwards ...
- PAT 1019 General Palindromic Number[简单]
1019 General Palindromic Number (20)(20 分) A number that will be the same when it is written forward ...
随机推荐
- Sequence Models Week 1 Improvise a Jazz Solo with an LSTM Network
Improvise a Jazz Solo with an LSTM Network Welcome to your final programming assignment of this week ...
- 选择排序_python
def selectdata(ls): for i in range(len(ls)): index=i for j in range(i+1,len(ls)): if ls[j]<ls[ind ...
- 18 12 30 服务器 Django 的初步使用 环境变量的调整
1.安装django 1.1.下载Django包 https://www.djangoproject.com/download/https://www.djangoproject.com/m/rele ...
- Linq------连表查询
1 List<Student> list = new List<Student>() { ,sex="男"}, ,sex="男"}, , ...
- .NET技术-4.0. NETCORE跨域
.NET技术-4.0. NETCORE跨域 1.安装程序CORS程序包,一般默认都带了此程序包的 Install-Package Microsoft.AspNetCore.Mvc.Cors 2.配置C ...
- libcurl在windows下的使用
curl在linux下很好用,但到了windows下写程序却没办法使用了,这时候可以使用libcurl库 libcurl库的编译网上很多,我就不一一赘述了,curl的官方网站:https://curl ...
- vue项目 首页开发 part3
da当拖动图标时候,只有上部分可以,下部分无响应 swiper 为根页面引用,其中的css为独立,点击swiper标签可以看见其包裹区域只有部分 那么需要修改 就需要穿透样式 外部 >> ...
- Scala(一)——scala+Idea环境配置
Java虚拟机的确是很强大,有很多计算机语言可以运行在虚拟机上,完善了虚拟机上多语言编程. 近年来,大数据云计算,大数据的火爆也让一些小众语言火了起来,如Python,Scala等.这些语言编写简单, ...
- 写一个读取Excel表格的接口
# -*- coding: gbk -*-import xlrd class Canshu: def __init__(self,filepath): """ 创建文件对 ...
- python基础,if判断
一.计算机基础知识: 1.计算机基本组成:主板+CPU+内存 (CPU:主频,核数(16) 内存:大小,型号,主频 显卡:显存,位宽) 2.计算机最低层:电子电路,只能识别0和1. 二.pyt ...