为啥我的输出结果就是不对,求教
import sys inputs = sys.stdin.readlines() def process(): inputs_list = list(map(str, inputs[0].strip().split())) inputs_list = eval(inputs_list[0]) # print(input_list) # input_list = [2,3,2,3,2] # print(inputs_list) set_list = set(inputs_list) need_list = {} for i in set_list: need_list[i] = [] for idx, num_ in enumerate(inputs_list): need_list[num_].append(idx) copy_inputs = [-1 for i in range(len(inputs_list))] for k, v in need_list.items(): if len(v) == 2: copy_inputs[v[0]] = v[1] + 1 copy_inputs[v[1]] = v[0] + 1 else: pass return copy_inputs copy_inputs = process() print('[', end='') print(*copy_inputs, sep=',', end='') print(']', end='')
全部评论
(9) 回帖