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
 #include <iostream>
#include <vector>
using namespace std;
//此处11进制中的10就是10,而不是a
int main()
{
int N, b;
cin >> N >> b;
vector<int>v1, v2;
while (N)
{
v1.push_back(N%b);
N /= b;
}
v2.assign(v1.rbegin(), v1.rend());
if (v1 == v2)
cout << "Yes" << endl;
else
cout << "No" << endl;
if (v2.size() == )
cout << ;
else
{
cout << v2[];
for (int i = ; i < v2.size(); ++i)
cout << " " << v2[i];
}
cout << endl;
return ;
}

PAT甲级——A1019 General Palindromic Number的更多相关文章

  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 (进制转换,vector运用,一开始2个测试点没过)

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

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

  5. PAT 甲级 1019 General Palindromic Number

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

  6. PAT A1019 General Palindromic Number (20 分)——回文,进制转换

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

  7. [PAT] A1019 General Palindromic Number

    [题目] https://pintia.cn/problem-sets/994805342720868352/problems/994805487143337984 题目大意:给定一个N和b,求N在b ...

  8. A1019. General Palindromic Number

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

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

随机推荐

  1. 海量数据解决思路之Hash算法

    海量数据解决思路之Hash算法   一.概述 本文将粗略讲述一下Hash算法的概念特性,里边会结合 分布式系统负载均衡 实例对Hash的一致性做深入探讨.另外,探讨一下Hash算法在海量数据处理方案中 ...

  2. 三种方法实现MNIST 手写数字识别

    MNIST数据集下载: import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist ...

  3. LVS/Nginx/HAProxy负载均衡器的对比分析

    转自:http://www.blogjava.net/ivanwan/archive/2013/12/25/408014.html LVS的特点是: 抗负载能力强.是工作在网络4层之上仅作分发之用,没 ...

  4. JQuery和JavaScript常用方法的一些区别

    jquery 就对javascript的一个扩展,封装,就是让javascript更好用,更简单,为了说明区别,下面与大家分享下JavaScript 与JQuery 常用方法比较   jquery 就 ...

  5. 基于windows消息的响应USB插入或取出

    导语:当有设备进入windows时,系统会向所有的应用层发送WM_DEVICECHANGE消息.进一步根据相应的事件判断设备. LRESULT CALLBACK WndProc(HWND hWnd, ...

  6. [记]Cordova安装插件选择插件版本

    在项目中可以使用 cordova plugin add [PLUGIN_ID] 這个命令安装一个cordova插件,这个命令好像是安装插件的最新版本.当需要通过cordova下载这个插件一个特定的版本 ...

  7. html---三列布局

    三列布局 1一 1.两边固定 当中自适应 2.当中列要完整显示 3.当中列要优先加载 <!DOCTYPE html> <html> <head> <meta ...

  8. [JZOJ5232] 【NOIP2017模拟A组模拟8.5】带权排序

    题目 题目大意 有一个数列AAA,数列上的每个数都是在[li,ri][l_i,r_i][li​,ri​]范围内随机的数. 将这个数列进行稳定排序,得到每个位置在排序后的排名pip_ipi​. f(A) ...

  9. 0908NOIP模拟测试赛后总结

    %%%skyh rank1- 奶风神.kx.有钱人 rank2-210 NC锅.RNB.B哥 rank5-200 我 rank32- 9-13upd:无意中点进了某个博客发现我竟然考场上yy出了树上莫 ...

  10. 0823NOIP模拟测试赛后总结

    考了两场感觉虚了... NOIP模拟测试30 分着考的. 就只有T2的美妙的暴力拿分了,60分rank10,挂了. T1是一道sb题,爆零了十分遗憾. 许多人都掉进了输出格式的坑里,C没大写.少个空格 ...