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

题目分析:按照求在不同进制下的数 来就十进制数 与原数进行比较
 #define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int Array[];
int Tag;
int main()
{
int N, b;
cin >> N >> b;
int n = ;
int temp = N;
int t=;
while (N)
{
t = N % b;
Array[Tag++] = t;
n = n*b + t;
N /= b;
}
if (n == temp)
cout << "Yes"<<endl;
else
cout << "No"<<endl;
cout << Array[--Tag];
while (Tag)
cout << " " << Array[--Tag];
return ;
}

1019 General Palindromic Number (20 分)的更多相关文章

  1. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

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

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

  4. 【PAT甲级】1019 General Palindromic Number (20 分)

    题意: 输入两个正整数n和b(n<=1e9,2<=b<=1e9),分别表示数字的大小和进制大小,求在b进制下n是否是一个回文串,输出“Yes”or“No”,并将数字n在b进制下打印出 ...

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

  6. 1019. General Palindromic Number (20)

    生词以及在文中意思 forward 向前地 backward 向后地 palindromic 回文的 base 基数(如十进制的10 和二进制的2) numeral system 数制 decimal ...

  7. PAT (Advanced Level) 1019. General Palindromic Number (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  8. PAT甲题题解-1019. General Palindromic Number (20)-又是水题一枚

    n转化为b进制的格式,问你该格式是否为回文数字(即正着写和倒着写一样)输出Yes或者No并且输出该格式又是水题... #include <iostream> #include <cs ...

  9. PAT A1019 General Palindromic Number (20 分)

    AC代码 #include <cstdio> const int max_n = 1000; long long ans[max_n]; int num = 0; void change( ...

随机推荐

  1. CentOS7系统更换软件安装源

    1.备份你的原镜像文件,以免出错后可以恢复. cp /etc/yum.repos.d/CentOS-Base.repo{,.backup} # 或者 mv /etc/yum.repos.d/CentO ...

  2. 原生JavaScript下的Ajax

    概述 AJAX即asynchronous javascript and XML,中文翻译是异步的javascript和XML.是指一种创建交互式网页应用.用于创建快速动态网页的开发技术. 传统的网页( ...

  3. (转)浅析epoll – epoll函数深入讲解

    原文地址:http://www.cppfans.org/1418.html 浅析epoll – epoll函数深入讲解 前一篇大致讲了一下epoll是个什么东西,优点等内容,这篇延续上一篇的内容,主要 ...

  4. 建议8:恰当选用if和switch

    相对来说下面几种情况更适合switch结构 枚举表达式的值.这种枚举是可以期望的,平行逻辑关系的 表达式的值具有离散性,不具有线性的非连续的区间值 表达式的值是固定的,不是动态变化的 表达式的值是有限 ...

  5. 手把手构建LSTM的向前传播(Building a LSTM step by step)

      本篇是在之前两篇基础上接着写的: 吴恩达deepLearning.ai循环神经网络RNN学习笔记(理论篇) 从头构建循环神经网络RNN的向前传播(rnn in pure python) 也可以不看 ...

  6. 神器cut基因剪

    cut cut 不就是切嘛,没错就是它--我给他起了一个外号基因剪刀 来我们学一下怎么使用这个命令 cut --help [root@ESProbe ~]# cut --help Usage: cut ...

  7. emWin模拟器Visual Studio开发时无法printf打印的问题

    1.emWin模拟器 为了方便用户学习evWin框架,Segger设计了一个PC仿真的工具,可以测试绝大部分GUI的功能,除了方便使用者学习之外,还可以加速项目开发进度.毕竟在PC上用Visual S ...

  8. DS01-线性表

    0.PTA得分截图 1.本周内容总结 1.1总结线性表内容 顺序表结构体定义 typedef struct LNode *List struct LNode { ElementType Data[MA ...

  9. MySQL:GROUP_CONCAT函数的使用

    原文链接 GROUP_CONCAT功能 将某个字段的值拼接成字符串. 举例使用 先看一下原始数据表 执行下面sql语句 SELECT `cid`,GROUP_CONCAT(mid) AS `mids` ...

  10. shell脚本基础-语法

    一 变量 [root@T_FOOT-Home2-ZZZ01 ~]# a=hello [root@T_FOOT-Home2-ZZZ01 ~]# echo $a hello [root@T_FOOT-Ho ...