题解 | #数据分类处理#
数据分类处理
https://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd
while 1: try: I0 = input().split() I = I0[1:] I_num = int(I0[0]) R0 = input().split() R = list(set(list(map(int, R0[1:])))) R = sorted(R) output_list = [] counter = 0 for i in range(len(R)): output_list.append(str(R[i])) output_list.append(' ') count_idx = output_list.index(' ') for j in range(len(I)): if str(R[i]) in I[j]: counter += 1 output_list.append(str(j)) output_list.append(I[j]) if counter != 0: output_list[count_idx] = str(counter) counter = 0 elif counter == 0: output_list.pop() output_list.pop() output_list.insert(0, str(len(output_list))) print(' '.join(output_list)) except: break