腾讯后端+综合卷笔试题(第一题和最后一题)
#腾讯8.17笔试第一题 def jieya(ans): left_index = 0 right_index = 0 shu_index = 0 # HG[3|B[2|CA]]F for i in range(len(ans)): if ans[i] == '[': left_index = i elif ans[i] == ']': right_index = i break elif ans[i] == '|': shu_index = i if right_index == 0: return ans cur = ans[shu_index + 1:right_index] * int(ans[left_index + 1:shu_index]) new_str = ans[:left_index] + cur + ans[right_index + 1:] return jieya(new_str) ans = "HG[3|B[2|CA]]F" print(jieya(ans))
#腾讯8.17笔试第五题 def xiuxi(pre_day, g, j, day): if day >= len(g): return 0 if not pre_day: if not g[day] and not j[day]: return xiuxi(pre_day, g, j, day + 1) + 1 else: return min(xiuxi(not pre_day, g, j, day + 1), xiuxi(pre_day, g, j, day + 1) + 1) else: return xiuxi(not pre_day, g, j, day + 1) + 1 pre_day = False g = [1, 1, 0, 0] j = [0, 1, 1, 0] print(xiuxi(pre_day, g, j, 0))自测过了,第五题检测的时候没出结果就被交卷了
#腾讯##笔试题目##题解#