小米9.15测试开发笔试
1.合数就分解,质数输出本身。
import math def fenjie(n): res=[] u=math.sqrt(n) for i in range(2,int(u)+1): while n%i==0: res.append(i) n=n/i if n!=1: res.append(n) print(res) fenjie(12)
2.给出一个包含字母的二维表格和一个单词,判断能否从表格某位置出发,得到该单词。
biaoge = [] while 1: s = input() if ',' in s: biaoge.append(s.split(',')) else: break word = s def dongzuo(i,j,word,visited): if not word: return True if 0<=i<len(biaoge) and 0<=j<len(biaoge[0]) and biaoge[i][j]==word[0] and visited[i][j]==0: visited[i][j]=1 return dongzuo(i-1,j,word[1:],visited) or dongzuo(i+1,j,word[1:],visited) or dongzuo(i,j+1,word[1:],visited) or dongzuo(i,j-1,word[1:],visited) else: return False def run(): for i in range(len(biaoge)): for j in range(len(biaoge[0])): visited = [[0 for _ in range(len(biaoge[0]))]for _ in range(len(biaoge))] if dongzuo(i,j,word,visited): print('true') return print('fasle') run()