题解 | #数据分类处理#
数据分类处理
http://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd
排序的时候,需要转换为数字,然后再转换为字符串:
listall=[]
while True:
try:
ii=input().split()[1:]
rr=input().split()[1:]
list1=[]
rrlist=[]
for i in rr:
if int(i) not in rrlist:
rrlist.append(int(i))
# rrlist.append(i)
rrlist.sort()
for i in range(len(rrlist)):
rrlist[i]=str(rrlist[i])
# print('rrlist',rrlist)
for i in range(len(rrlist)):
listtemp=[]
for j in range(len(ii)):
if rrlist[i] in ii[j]:
listtemp.extend([j,ii[j]])
if len(listtemp)!=0:
listtemp.insert(0, len(listtemp)//2)
listtemp.insert(0, rrlist[i])
list1.extend(listtemp)
list1.insert(0, len(list1))
listall.append(list1)
except:
break
# print('temp',listtemp)
for i in range(len(listall)):
for j in range(len(listall[i])):
if j!=len(listall[i])-1:
print(listall[i][j],end=' ')
else:
print(listall[i][j])
while True:
try:
ii=input().split()[1:]
rr=input().split()[1:]
list1=[]
rrlist=[]
for i in rr:
if int(i) not in rrlist:
rrlist.append(int(i))
# rrlist.append(i)
rrlist.sort()
for i in range(len(rrlist)):
rrlist[i]=str(rrlist[i])
# print('rrlist',rrlist)
for i in range(len(rrlist)):
listtemp=[]
for j in range(len(ii)):
if rrlist[i] in ii[j]:
listtemp.extend([j,ii[j]])
if len(listtemp)!=0:
listtemp.insert(0, len(listtemp)//2)
listtemp.insert(0, rrlist[i])
list1.extend(listtemp)
list1.insert(0, len(list1))
listall.append(list1)
except:
break
# print('temp',listtemp)
for i in range(len(listall)):
for j in range(len(listall[i])):
if j!=len(listall[i])-1:
print(listall[i][j],end=' ')
else:
print(listall[i][j])