题解 | #数据分类处理#

数据分类处理

https://www.nowcoder.com/practice/9a763ed59c7243bd8ab706b2da52b7fd

读题两小时,编码五分钟

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    const [n,...I] = (await readline()).split(" ");
    let [m,...R] =  (await readline()).split(" ");
    R = [...new Set(R)].sort((a,b)=>a-b);//排序去重
    m = R.length;
    let res =  Array.from(Array(m),()=>[]);
    for(let i = 0; i < n; i ++){
        for(let j = 0; j < m; j++){
            if(I[i].indexOf(R[j]) != -1) {
                res[j].push(i,I[i]);
            }           
        }
    }
    res = res.map((item,index)=>item.length?[R[index],item.length/2,...item]:item);
    res = res.reduce((pre,cur)=>[...pre,...cur]);
    console.log(res.length,...res);
}()

全部评论

相关推荐

饼子吃到撑:学院本是这样的,找工作拼运气,你技术再好人家筛选学历照样沉入海底,海投就行了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务