HJ3 明明的随机数

80 阅读1分钟

image.png

image.png

const rl = require("readline").createInterface({ input: process.stdin });

void (async function () {
    // Write your code here
    const nums = []; // 存待排序的所有数字
    const clearNums = []; // 存去重后的数字
    rl.on("line", function (line) {
        nums.push(Number(line));
        if (nums.length - 1 === nums[0]) {
            nums.shift(); // 去掉首位表示输入数据数量的数字
            nums.forEach((f) => {
                if (!clearNums.includes(f)) {
                    clearNums.push(f); //  已存在的数字不重复添加
                }
            });
            // 对去重之后的数据进行排序
            clearNums.sort((a, b) => {
                return a - b;
            });
            clearNums.forEach((f) => console.log(f));
        }
    });
})();

明明的随机数_牛客题霸_牛客网 (nowcoder.com)