牛客网 jsv8 acm

牛客网输入输出(js v8)

引入接口函数

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

函数---IIFF

// 这样写
(async function () {
    /**code */
})();
// 或者
void (async function () {
    /**code */
})();

输入---readline

处理单行输入:

// a b
const line = await readline();
const tokens = line.split(" ");
const a = parseInt(tokens[0]);
const b = parseInt(tokens[1]);

// 数字字符输入,直接转为整数
const nums = line.split(" ").map(Number);

// 字符串数组排序
const arr = line.split(" ");
arr.sort((t1, t2) => t1.localeCompare(t2));

处理多行输入:

let line;
while ((line = readline())) {
    /**code */
}

输出---console.log

posted @   chuxin_jian  阅读(100)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示