题解 | #成绩排序#
成绩排序
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 length = await readline() length = parseInt(length.split(' ')[0]) let isGrow = await readline() isGrow = parseInt(isGrow.split(' ')[0]) const arr = [] while(line = await readline()){ let tokens = line.split(' '); let name = tokens[0]; let score = parseInt(tokens[1]); arr.push({ name, score }) } arr.sort((a, b) => { if (isGrow) { return a.score - b.score } return b.score - a.score }) arr.forEach(item => { console.log(`${item.name} ${item.score}`) }) }()