题解 | #成绩排序#

成绩排序

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

全部评论

相关推荐

11-18 15:57
门头沟学院 Java
最终归宿是测开:这个重邮的大佬在重邮很有名的,他就喜欢打92的脸,越有人质疑他,他越觉得爽😂
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务