滴滴8.21 测开笔试
第一题:暴力 AC
n=input() str1=input().split() str2=input().split() len1=len(str1) len2=len(str2) index1=str1.index('X') index2=str2.index('X') res1=[] res2=[] for i in range(index1): for j in range(index2): if str1[i]==str2[j]: res1.append(str1[i]) n1=len(res1) for i in range(index1,len1): for j in range(index2,len2): if str1[i]==str2[j]: res2.append(str1[i]) n2=len(res2) print(n1+1,end=' ') print(n-n2)
第二题:
螺旋打印斐波那契矩阵
忘记n平方了,GG
n=int(input()) tar=n**2 l,r,t,b=0,n-1,0,n-1 ans=[[0]*n for _ in range(n)] num=[1] count=0 a1,a2=0,1 for _ in range(n*n-1): a1,a2=a2,a1+a2 num.append(a2) for _ in range(n): for i in range(l,r+1): if num: ans[t][i]=num[-1] num.pop() t+=1 for i in range(t,b+1): if num: ans[i][r]=num[-1] num.pop() r-=1 for i in range(r,l-1,-1): if num: ans[b][i]=num[-1] num.pop() b-=1 for i in range(b,t-1,-1): if num: ans[i][l]=num[-1] num.pop() l+=1 print(ans)