题解 | #数据分类处理#
数据分类处理
http://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd
let map = {}; let rArr = readline().split(" "); rArr.shift(); let llArr = readline().split(" "); llArr.shift(); let lArr = [...new Set(llArr)].sort((a, b) => a - b); lArr.forEach((la) => { map[la] = {}; rArr.forEach((ra, index) => { if (ra.indexOf(la) > -1) { map[la][index] = ra; } }); });
let result = []; Object.keys(map).forEach((item) => { let child = map[item]; if (Object.keys(child).length > 0) { result.push(item); result.push(Object.keys(child).length); Object.keys(child).forEach((ckey) => { result.push(ckey); result.push(child[ckey]); }); } }); let len = result.length; result.unshift(len); console.log(result.join(" "));