1019 General Palindromic Number (20 分)
Input Specification:
Output Specification:
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
作者:CHEN, Yue
单位:浙江大学
代码长度限制:16 KB
时间限制:400 ms
内存限制:64 MB
题目大意
就是给你两个数字,判断第一个数字按照第二个数字进行进制转换后,是否是回文数。若是的话,输出Yes,下一行输出转换后的数字;若不是,输出No,下一行输出转换后的数字。
解题思路
- 先把题中是数字进行进制的转换。
- 然后判断转换完的数字是否是回文数。
- 最后按照题中要求格式进行输出。
Code
def func():
l=list(map(int,input('').split( )))
n=l[0]
b=l[1]
s=[]
sum=1
while n!=0:#基本数制转换方法
sum=n%b
s.append(sum)
n=n//b
tag=0
s1=s[::-1]#记得逆序输出
if s1 == s:
tag = 1
if tag==1:
print("Yes")
else:
print("No")
s=s[::-1]#记得逆序输出
for i in range(len(s)):
if i!=0:
print(' ',end='')
print(str(s[i]),end='')
func()
运行结果