var __readline = require('readline-sync'); __readline.setDefaultOptions({ prompt: '' }); var read_line = __readline.prompt; var print = console.log;
这样子,JS带输入输出就OK了
JavaScript(V8)
单行输入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
var __readline = require('readline-sync'); __readline.setDefaultOptions({ prompt: '' }); var read_line = __readline.prompt; var print = console.log;
//牛客网:readline //赛码:read_line while(line=read_line()){ var lines = line.split(' '); var a = parseInt(lines[0]); var b = parseInt(lines[1]); print(a+b); }
多行输入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
var __readline = require('readline-sync'); __readline.setDefaultOptions({ prompt: '' }); var read_line = __readline.prompt; var print = console.log;
var countLine = parseInt(read_line()); var sum = 0; for (var i = 0; i < countLine; i++) { lines = read_line().split(" ") for (var j = 0; j < lines.length; j++) { sum += parseInt(lines[j]); } print(sum); }
var print = console.log; var readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
var countLine = 3; var index = 0; var sum = 0; rl.on('line', function (line) { var lines = line.split(' '); for (var i = 0; i < lines.length; i++) { sum += parseInt(lines[i]); } index++; if (index == countLine) { print(sum); // 关闭node输入环境 rl.close(); } }); rl.on('close', function () { process.exit(0); })