题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { // Write your code here let num = parseInt(await readline()); let sort = await readline(); let arr = []; while(line = await readline()){ let temp = line.split(' '); arr.push(temp); } // console.log(arr); if(sort == '0'){ arr.sort((a,b) => parseInt(b[1]) - parseInt(a[1])); }else{ arr.sort((a,b) => parseInt(a[1]) - parseInt(b[1])); } for(let k of arr){ console.log(k.join(' ')); } }()
代码请参考: