华为笔试ak求个面试
华为笔试相比其他大厂还真是简单呀,一个小时ak,许愿个面试
同时许愿百度实习oc,微保二面通过
贴个二三题代码吧
第二题:
''' 5a 12 5b ba 34 5b bb 88 05 5a 75 cd bb 62 5a 34 cd 78 cc da fb 06 5a ''' strs = input().strip().split(" ") last_flag=0 tmp_num=[] tmp_length=0 res_list=["5a"] i=1 while(i<len(strs)): #print(tmp_num,res_list) if strs[i]=="5a": target_num=int(strs[i-1],16) #print(target_num,tmp_num) if tmp_length==target_num+1: res_list.extend(tmp_num.copy()) res_list.append("5a") last_flag=i tmp_num=[] tmp_length=0 elif strs[i]=="5b": if i+1<len(strs): if strs[i+1]=="ba": tmp_num.append("5b") tmp_num.append("ba") tmp_length+=1 elif strs[i+1]=="bb": tmp_num.append("5b") tmp_num.append("bb") tmp_length+=1 i+=1 else: tmp_num.append(strs[i]) tmp_length += 1 i+=1 for i in range(len(res_list)-1): print(res_list[i],end=" ") print(res_list[-1])
第三题:
dfs所有可能情况即可
''' 9 3 100 200 300 400 500 600 700 800 900 ''' m,k=input().strip().split(" ") m=int(m) k=int(k) nums=input().strip().split(" ") nums=[int(nums[i]) for i in range(len(nums))] sums=[nums[0]] for i in range(1,len(nums)): sums.append(sums[-1]+nums[i]) res=[] max_val=0 def dfs(level,start_index,tmp_res): global max_val,res,m if level==k: min_val=sums[tmp_res[0]-1] for i in range(1,len(tmp_res)): min_val=min(min_val,sums[tmp_res[i]-1]-sums[tmp_res[i-1]-1]) min_val=min(min_val,sums[-1]-sums[tmp_res[-1]-1]) if min_val>max_val: max_val=min_val res=tmp_res else: for i in range(start_index+1,m): tp=tmp_res.copy() tp.append(i) dfs(level+1,i,tp) dfs(1,0,[]) #print(res,max_val) for i in range(len(nums)-1): if i in res: print("/ "+ str(nums[i]),end=" ") else: print(nums[i],end=" ") if len(nums)-1 in res: print("/ "+str(nums[-1])) else: print(nums[-1])