到牛客网的ACM模式去做了一点简单的测试.
如有错误欢迎指正与讨论,有详细的学习链接也欢迎分享。
JavaScript Node
// 主体函数
function calc(a, b) {
a = parseInt(a);
b = parseInt(b);
return a + b
}
// Process the input
const { count } = require('console');
var fs = require('fs');
var buf = '';
// 处理输入
process.stdin.on('readable', function () {
var chunk = process.stdin.read();
if (chunk)
buf += chunk.toString();
});
// 处理输出
process.stdin.on('end', function () {
buf.split('\n').forEach(function (line) {
var tokens = line.split(' '); // 相当于获取了输入,拿到的是字符串
console.log(tokens.reduce(calc)); // 加入函数名
});
});
测试:
function calc(a, b) {
a = parseInt(a);
b = parseInt(b);
return a + b
}
// Process the input
const {
count } = require('console');
var fs = require('fs');
var buf = '';
// 处理输入
process.stdin.on('readable', function () {
var chunk = process.stdin.read();
if (chunk)
buf += chunk.