题解 | #数据分类处理#

数据分类处理

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

全部评论

相关推荐

昨天 12:07
门头沟学院 Java
勇敢牛牛不怕困难
投递OPPO等公司9个岗位
点赞 评论 收藏
分享
06-07 17:17
嘉兴学院 教师
单单人旁的佳:你是我见过最美的牛客女孩
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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