博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1019 General Palindromic Number (20 分)
阅读量:4837 次
发布时间:2019-06-11

本文共 2000 字,大约阅读时间需要 6 分钟。

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 b2, where it is written in standard notation with k+1 digits ai​​ as i=0k​​(ai​​bi​​). Here, as usual, 0ai​​<b for all i and ak​​ is non-zero. Then N is palindromic if and only if ai​​=aki​​ 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<N109​​ is the decimal number and 2b109​​ 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​​ ak1​​ ... a0​​". Notice that there must be no extra space at the end of output.

Sample Input 1:

27 2

Sample Output 1:

Yes1 1 0 1 1

Sample Input 2:

121 5

Sample Output 2:

No4 4 1

水题:进制转换,判断是否回文

 

1 /** 2 * Copyright(c) 3 * All rights reserved. 4 * Author : Mered1th 5 * Date : 2019-02-24-01.08.29 6 * Description : A1019 7 */ 8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 using namespace std;19 const int maxn=1010;20 bool judge(int s[],int len){21 for(int i=0;i
=0;i--){47 printf("%d",s[i]);48 if(i>0) printf(" ");49 }50 return 0;51 }

 

转载于:https://www.cnblogs.com/Mered1th/p/10425160.html

你可能感兴趣的文章
Rxjava+Retrofit2+Okhttp3多文件上传(服务器端代码+客户端代码)
查看>>
Spring系列之bean的使用
查看>>
Mac下lombok无法安装到eclipse mars
查看>>
Mac下为什么有的文件名后带一个* 星号?
查看>>
Hololens入门之语音识别(语音命令)
查看>>
python_day09 多进程 多线程 协程 paramiko模块
查看>>
学习WPF之 Binding
查看>>
Windows7系统下Oracle数据库安装的oracle net configuration assistant失败问题
查看>>
umeditor 踩坑
查看>>
luogu P1854 花店橱窗布置
查看>>
6-6 小球下落 uva679
查看>>
Victor and World 状压dp
查看>>
vim 常用设置
查看>>
NGUI所见即所得之UIAtlasMaker , UIAtlas (2)
查看>>
Dynamics AX 2012 R2 耗尽用户
查看>>
项目引入非配置的文件,打成war包后测试报错的可能原因
查看>>
ubuntu更改apache2根目录
查看>>
Hibernate配置属性
查看>>
hibernate.properties
查看>>
那些可能被你忽略的MySQL优化技巧
查看>>