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 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+1digits 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
转换为某进制数后在判断是否为回文数
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int a[];
int n,m;
void _deal(int x,int y)
{
int t=;
while(x){
a[t++]=x%y;
x/=y;
}
int flag=;
for(int i=;i<=t/;i++){
if(a[i]!=a[t-i-]){
flag=;
break;
}
}
if(flag) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
for(int i=t-;i>=;i--){
if(i==) cout<<a[i]<<endl;
else cout<<a[i]<<" ";
}
}
int main()
{
while(cin>>n>>m){
_deal(n,m);
}
return ;
}
PAT (Advanced Level) Practice 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 Level) Practice 1027 Colors in Mars (20 分) 凌宸1642
PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...
- PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642
PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...
- PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642
PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...
- PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642
PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642 题目描述: Calculate a+b and output the sum i ...
- PAT (Advanced Level) Practice 1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...
- 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 ...
- 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进制的格式,问你该格式是否为回文数字(即正着写和倒着写一样)输出Yes或者No并且输出该格式又是水题... #include <iostream> #include <cs ...
随机推荐
- Java框架之SpringSecurity-权限系统
SpringSecurity SpringSecurity融合Spring技术栈,提供JavaEE应用的整体安全解决方案:提供全面的安全服务.Spring Security支持广泛的认证模型 模块划分 ...
- 从底层入手,解析字节码增强和Btrace应用
这篇文章聊下字节码和相关的应用. 1.机器码和字节码 机器码(machine code),学名机器语言指令,有时也被称为原生码(Native Code),是电脑的CPU可直接解读的数据. 通常意义上来 ...
- OpenCV图像变换二 投影变换与极坐标变换实现圆形图像修正
投影变换 在放射变换中,物体是在二维空间中变换的.如果物体在三维空间中发生了旋转,那么这种变换就成为投影变换,在投影变换中就会出现阴影或者遮挡,我们可以运用二维投影对三维投影变换进行模块化,来处理阴影 ...
- Java笔记---枚举类和注解
Java笔记---枚举类和注解 一.枚举类 自定义枚举类 方式一:JDK5.0之前自定义枚举类 class Seasons { //1. 声明Seasons对象的属性 private final St ...
- mysql随机抽取数据
-- 慢 ; -- 较慢 SELECT * FROM `table` WHERE id >= (SELECT floor( RAND() * ((SELECT MAX(id) FROM `t ...
- [VB.NET Tips]创建匿名类型列表
在调用一些Web API时经常要发送或接收一些数据,在构造Json时可能要创建一些类. 很多都是在调用相关方法才使用到这些类,那使用匿名类型是个不错的选择.如果要传些表结构数据时,就要创建List. ...
- powersploit的两个信息收集的脚本
0x00 简介 powersploit是基于powershell的渗透工具包,里面都是powershell的脚本工具文件.工具包地址:https://github.com/PowerShellMafi ...
- 《自拍教程21》mediainfo_多媒体文件查看工具
mediainfo命令介绍 mediainfo.exe(Linux/iMac下是未带后缀的mediainfo), 是一款音视频图片文件的信息查询工具, 常用于查看多媒体文件的视频流信息,音频流信息,字 ...
- viewpage+RadioButton+Fragment简单导航界面
https://blog.csdn.net/qibanxuehua/article/details/47333879
- MySQL基础(7) | 触发器
MySQL基础(7) | 触发器 基本语法 创建 CREATE TRIGGER trigger_name trigger_time trigger_event ON table_name FOR EA ...