分享我的华为2019-9-18软件题代码(1、3题)
第一题:
res = [] while True: try: nums = input().split() except Exception: break if len(nums[0]) == 2 and len(nums[-1]) == 2 and all(len(num) == 1 for num in nums[1:-1]): res.append('true') elif len(nums[0]) == 1 and len(nums[-1]) == 1 and all(len(num) == 2 for num in nums[1:-1]): res.append('true') elif len(nums[0]) == 1 and all(len(nums[i]) == 1 for i in range(0, len(nums), 2)) and all( len(nums[i]) == 2 for i in range(1, len(nums), 2)): res.append('true') elif len(nums[0]) == 2 and all(len(nums[i]) == 2 for i in range(0, len(nums), 2)) and all( len(nums[i]) == 1 for i in range(1, len(nums), 2)): res.append('true') else: res.append('false') print(' '.join(res))第三题:
cmd, content = input().split(':') if int(cmd) == 1: last_server_add_num = int(content.split('_')[1]) print((last_server_add_num - 1) * 50) elif int(cmd) == 2: ascii_sum = sum(ord(c) for c in content) print((((ascii_sum % 999 - 1) // 50 + 1) * 50) % 1000) elif int(cmd) == 3: servers, token = content.split(';') node_nums = [(int(x.split('_')[1]) - 1) * 50 for x in servers.split(',')] ascii_sum = sum(ord(c) for c in token) node = (((ascii_sum % 999 - 1) // 50 + 1) * 50) % 1000 if node in node_nums: node = (node + 50) % 1000 print(node) elif int(cmd) == 4: last_server_add_num = int(content.split('_')[-1]) if last_server_add_num % 2 == 1: print((last_server_add_num // 2) * 50 + 25) else: print(500 + (last_server_add_num // 2 - 1) * 50 + 25) elif int(cmd) == 5: token = content.split(';')[-1] server = content.split(';')[0] last_server_add_num = int(server.split('_')[-1]) add_servers = [] for i in range(1, last_server_add_num + 1): if i % 2 == 1: add_servers.append((i // 2) * 50 + 25) else: add_servers.append(500 + (i // 2 - 1) * 50 + 25) ascii_sum = sum(ord(c) for c in token) added_num = (((ascii_sum % 999 - 1) // 25 + 1) * 25) % 1000 non_added_num = (((ascii_sum % 999 - 1) // 50 + 1) * 50) % 1000 if added_num in add_servers: print(added_num) else: print(non_added_num)
秋招快结束了还是0offer,难受