题解 | #成绩排序#
成绩排序
https://www.nowcoder.com/practice/8e400fd9905747e4acc2aeed7240978b
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let inputs = [];
rl.on('line', function (line) {
inputs.push(line);
});
rl.on('close',function(){
let n = parseInt(inputs.shift());
let order = parseInt(inputs.shift());
inputs.sort((a,b)=>{
let score1 = a.match(/\d{1,3}/)[0];
let score2 = b.match(/\d{1,3}/)[0];
return order == 0?score2-score1:score1-score2;
}).forEach(x=>console.log(x))
})
#HJ68成绩排序#
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
let inputs = [];
rl.on('line', function (line) {
inputs.push(line);
});
rl.on('close',function(){
let n = parseInt(inputs.shift());
let order = parseInt(inputs.shift());
inputs.sort((a,b)=>{
let score1 = a.match(/\d{1,3}/)[0];
let score2 = b.match(/\d{1,3}/)[0];
return order == 0?score2-score1:score1-score2;
}).forEach(x=>console.log(x))
})
#HJ68成绩排序#