10道选择,3道编程,2h。
一、十进制转R进制(2~16)
def f(a, y): x=abs(a) #注意负数 if y < 10: z = [] while x != 0: z.append(x % y) x = x // y res = z[::-1] else: k = [] z = [] while x != 0: z.append(x % y) x = x // y for i in range(len(z)): if z[i] >= 10: z[i] = z[i] - 10 + ord('A') elif z[i] <= 9 and z[i] >= 0: z[i] = z[i] + ord('0') for i in range(len(z)): k.append(chr(z[i])) res = k[::-1] return res #主程序部分 a=23 b=12 res=f(a,b) x=[str(i) for i in res] #注意转成str类型 r=''.join(x) if a>=0: print(r) else: re='-'+r print(re)
二、取石子游戏:斐波那契数列
while True: try: n=int(input()) if n==0: break else: l=[[0] for i in range(50)] l[0]=l[1]=0 for i in range(2,50): l[i]=l[i-1]+l[i-2] while(n): flag=0 for i in range(50): if(l[i]===n): flag=1 if flag==1: print('Second win') else: print('First win') except: break
三、两个单词word1和word2,互相转换的最小操作数
动态规划。
(就不复现了,网上挺多的)
全部评论
(5) 回帖