参考代码:
def turn(n,m): #n进制的m转换为十进制(2~16进制通用) dic={'A':10,'B':11,'C':12,'D':13,'E':14,'F':15} m=str(m) ans=0 for item in m: if 'A'<=item<='F': item=dic[item] ans=ans*n+int(item) return ans def back(n,m): #十进制的m转换为n进制(2~16进制通用) dic = {10: 'A', 11: 'B', 12: 'C', 13: 'D', 14: 'E', 15: 'F'} ss='' while m!=0: tmp=m%n if 10<=tmp<=n: tmp=dic[tmp] ss=ss+str(tmp) m=m//n ss=ss[::-1] return ss def calculate(x): #判断回文 tmp=str(x) if tmp==tmp[::-1]: return True return False n=eval(input()) m=str(input().strip()) times=1 x=turn(n,m) rev=turn(n,m[::-1]) k=back(n,x+rev) while times<=30: if calculate(k)==True: print(f'STEP={times}') break else: x=turn(n,k) rev=turn(n,k[::-1]) k=back(n,x+rev) times+=1 if times>30: print('Impossible!')
0.0分
0 人评分
假币问题 (C++代码)(向上取整的一种处理方式)浏览:1664 |
C语言训练-邮票组合问题* (C语言代码)......浏览:650 |
A+B for Input-Output Practice (IV) (C语言代码)浏览:517 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:608 |
【偶数求和】 (C语言代码)浏览:646 |
WU-图形输出 (C++代码)浏览:802 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:678 |
数字游戏 (C++代码)浏览:1185 |
C二级辅导-进制转换 (C语言代码)浏览:661 |
永远的丰碑 (C语言代码)浏览:525 |