import re N = int(input()) ''' gifts6 and7 Exchanging1 all2 precious5 things8 kinds3 of4 ''' str = input().strip().split(" ") list = [] for i in range(len(str)): if str[i] != '': list.append(str[i]) else: continue num_list1 = [] str_list1 = [] dist = {} for i in range(N): num_list = re.findall('\d', list[i]) # 生成['1','2'] num_list = ''.join(num_list) # 把数组里面的值连接在一起形成一个字符串12 num_list1.append(num_list) # 把数组合并在一起 str_list = re.findall('[a-zA-Z]', list[i]) # 生成字符['g', 'i', 'f', 't', 's'] s = ''.join(str_list) # 数组连接在一起成字符gifts str_list1.append(s) for i in range(N): dist[int(num_list1[i])] = str_list1[i] dist_1 = sorted(dist.items(), key=lambda x: x[0]) x = [] for i, j in dist_1: x.append(j) print(" ".join(x))
【华为OD机试真题2023B卷 Python3】报文重传和重排序
于 2023-10-02 23:00:13 首次发布