7 回复
直接用Process对象即可喵~
process.stdin.on('data’, function (chunk) { process.stdout.write('data: ' + chunk); });
process.stdin.on('end’, function () { process.stdout.write(‘end’); });
举个例子吧,题目是AIZU OJ的A+B问题:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1000
代码如下:
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", function(chunk) {
var datas = chunk.trim().split("\n");
for(var i = 0; i < datas.length; i++) {
var ab = datas[i].trim().split(" ");
var a = parseInt(ab[0]);
var b = parseInt(ab[1]);
console.log(a + b);
}
});