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()
運行結果

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/261067.html
標籤:python
上一篇:Python繪制高斯曲線
