3.13美团笔试
第一题:列表翻转(直接转就行)
n, m = map(int, input().split()) aa = [] for i in range(n): aa.append([int(j) for j in input().split()]) res = [[0] * n for _ in range(m)] for i in range(n): for j in range(m): res[j][i] = aa[i][j] for i in range(m): for j in range(n): if j != n-1: print(res[i][j], end=" ") else: print(res[i][j])
s = input() res = [] cur = "" i = 0 while i < len(s): if '0' <= s[i] <= '9': cur += s[i] else: if cur != "": res.append(int(cur)) cur = "" i += 1 if cur != "": res.append(int(cur)) res.sort() for n in res: print(n)
> 直接找数,最后排个序
> 看别的笔经,好像存在大数问题,(python真香了) =_=第三题:众数问题。。(卡数据了,只过了73%,感觉已经挺优的了啊,滑窗思想,心碎了)
n, k = map(int, input().split()) nums = [int(i) for i in input().split()] #print(nums) cur_dic = {} res = [] if k == 1: for i in nums: print(i) elif k == 2: for i in range(0, len(nums)-1): if nums[i] <= nums[i+1]: print(nums[i]) else: print(nums[i+1]) else: for i in range(n): if cnt >= k: print(cur_dic) dic_cpy = sorted(cur_dic.items(), key=lambda x: (-x[1], x[0])) # print(cur_dic) res.append(dic_cpy[0][0]) if cur_dic[nums[i]] >= 1: cur_dic[nums[i]] -= 1 else: cur_dic.pop(nums[i]) if nums[i] not in cur_dic: cur_dic[nums[i]] = 1 else: cur_dic[nums[i]] += 1 #print(cur_dic) cnt += 1 for j in res: print(j)
剩下两道图,直接放弃了,最后一个读懂了,就是时间不够了,加上图做得少,还需加强练习!!!呜呜呜,好惨,给个实习机会吧!