题解 | #数据分类处理#

数据分类处理

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(" "));

全部评论

相关推荐

我即大橘:耐泡王
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务