华为,2019/9/7日,软件笔试题目
第一题 : AC 100 %
if __name__ == "__main__": nums = [int(x) for x in input().strip().split(' ')] n = len(nums) dp = [-1]*n dp[n-1] = 1 for i in range(n-2, 0, -1): tar = i + nums[i] if tar < n and dp[tar] >= 0: dp[i] = dp[tar] + 1 else: dp[i] = -1 if max(dp[1:n//2]) <= 0: print(-1) else: res = [x for x in dp[1:n//2] if x>=0] print(min(res))
第二题:
没做出来
第三题 : AC 100%
if __name__ == "__main__": bd, id, res = input().split(';') ids = id.split(',') for id in ids: a,b = id.split('=') bd = bd.replace(a,b) bd = bd.replace('{','') bd = bd.replace('}','') bds = bd.split(',') temp_dict = {} for bd in bds: a,b = bd.split('=') temp_dict.update({a:b}) s = temp_dict[res] temp_dict.pop(res)