题解 | #数据分类处理#
数据分类处理
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); }()