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

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

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);
    // }
}()

全部评论

相关推荐

fRank1e:吓得我不敢去外包了,但是目前也只有外包这一个实习,我还要继续去吗
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务