题解 | 【模板】序列操作

【模板】序列操作

https://www.nowcoder.com/practice/12da4185c0bb45918cfdc3072e544069

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 count = 0;
    const arr = [];
    while(line = await readline()){
        if(count > 0){
            let tokens = line.split(' ');
            let a = parseInt(tokens[0]);
            let b = parseInt(tokens[1]);
            let c = parseInt(tokens[2]);
            if(a === 1) arr.push(b);
            if(a === 2) arr.pop();
            if(a === 3) console.log(arr[b]);
            if(a === 4) arr.splice(b+1, 0, c);
            if(a === 5) arr.sort((p,q)=>p-q);
            if(a === 6) arr.sort((p,q)=>q-p);
            if(a === 7) console.log(arr.length);
            if(a === 8) console.log(arr.join(' '));
        }
        count++
    }
}()

全部评论

相关推荐

牛客44320985...:你的当务之急是把这个糖的要死的沟槽ide主题改了
点赞 评论 收藏
分享
想踩缝纫机的小师弟练...:不理解你们这些人,要放记录就把对方公司名字放出来啊。不然怎么网暴他们
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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