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 (. 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
题目分析:按照求在不同进制下的数 来就十进制数 与原数进行比较
#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 分)的更多相关文章
- 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 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 ...
- 【PAT甲级】1019 General Palindromic Number (20 分)
题意: 输入两个正整数n和b(n<=1e9,2<=b<=1e9),分别表示数字的大小和进制大小,求在b进制下n是否是一个回文串,输出“Yes”or“No”,并将数字n在b进制下打印出 ...
- 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 ...
- 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 ...
- PAT A1019 General Palindromic Number (20 分)
AC代码 #include <cstdio> const int max_n = 1000; long long ans[max_n]; int num = 0; void change( ...
随机推荐
- Androidstudio实现一个简易的加法器——分享两种方法实现(日常作业练习)
Androidstudio实现一个简易的加法器——分享两种方法实现(日常作业练习) ...
- Redis05——Redis Cluster 如何实现分布式集群
前面一片文章,我们已经说了Redis的主从集群及其哨兵模式.本文将继续介绍Redis的分布式集群. 在高并发场景下,单个Redis实例往往不能满足业务需求.单个Redis数据量过大会导致RDB文件过大 ...
- Simulink仿真入门到精通(二) Simulink模块
2.1 Simulink模块的组成要素 用户构建系统模型时无需直接面对成千上万行的代码,而是通过模块化图形界面以模块化的方式构建,能够使理解变得容易,让大脑减负.通过层次化模块分布将系统功能模块化,而 ...
- 初识JVM:(一)JVM工作原理和流程
本文主要参考:http://blog.csdn.net/CSDN_980979768/article/details/47281037?locationNum=7&fps=1 声明:主要用于个 ...
- Block详解一(底层分析)
本篇博客不再讲述Block的基本定义使用,最近而是看了很多的block博客讲述的太乱太杂,所以抽出时间整理下block的相关底层知识,在讲述之前,提出几个问题,如果都可以回答出来以及知道原理,大神绕过 ...
- ZooKeeper原理解析
目录 ZooKeeper中的各种角色 ZooKeeper与客户端 Zookeeper节点数据操作流程 Paxos 算法概述(ZAB 协议) ZooKeeper 的选主机制 选择机制中的概念 选举消息内 ...
- 为了弄懂Flutter的状态管理, 我用10种方法改造了counter app
为了弄懂Flutter的状态管理, 我用10种方法改造了counter app 本文通过改造flutter的counter app, 展示不同的状态管理方法的用法. 可以直接去demo地址看代码: h ...
- 如何配置 GitHub 为个人的手机图床
PicPlus 是一个手机端的图床上传工具,支持七牛云.阿里云.又拍云等主流图床配置,同时还支持配置 GitHub.码云作为自己的图床,如下所示: 这篇文章主要介绍如何在 PicPlus 中配置 Gi ...
- 快速上手项目远程团队协作--CODING(新手向)
快速上手项目远程团队协作--CODING(新手向) CODING网址:https://e.coding.net/signin 前言:之前用过github,用过微软的Azure协作(https://az ...
- Fiddler4 手机抓包
1.要对计算机Fiddler进行配置,允许远程计算机连接. 2.保证手机电脑在同一局域网中. 3.手机上设置代理服务器.以华为手机为例,设置-->WLAN-->找到并长按目前所连接的WiF ...