题解 | #输入整型数组和排序标识,对其元素排序#

输入整型数组和排序标识,对其元素按照升序或降序进行排序

https://www.nowcoder.com/practice/dd0c6b26c9e541f5b935047ff4156309

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    let length = await readline();
    let input = await readline();
    let condition = await readline();
    input = input.split(' ').map((e)=> parseInt(e));
    if(condition == 0){
        input.sort((a, b) => a - b)
    }
    else if(condition == 1){
        input.sort((a, b) => b - a)
    }
    console.log(input.join(' '))
    // Write your code here
    // while(line = await readline()){
    //     let tokens = line.split(' ');
    //     let a = parseInt(tokens[0]);
    //     let b = parseInt(tokens[1]);
    //     console.log(a + b);
    // }
}()

全部评论

相关推荐

01-24 12:50
门头沟学院 C++
投票
菜狗二号:还有啥想的 指定国有行啊,去了就开始幸福美满的生活了,选华子不是折腾自己么,最终财富积累度是差不多的,但是幸福指数是相差甚远的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务