题解 | 数据分类处理
数据分类处理
https://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd
I = input().split()[1:]
R = input().split()[1:]
r = list(map(str, sorted(set(map(int, R)))))
res = []
lenRes = 0
for rule in r:
res1 = []
for id, data in enumerate(I):
if rule in data:
res1.append(id)
res1.append(int(data))
if res1:
res.append([rule, len(res1)//2] + list(map(int, res1)))
lenRes += (len(res1) + 2)
print(lenRes, end = " ")
for re in res:
if re[1] > 0:
print(" ".join(map(str, re)), end = " ")
查看10道真题和解析