题解 | 【模板】序列操作
【模板】序列操作
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++
}
}()
