参考:https://www.cnblogs.com/yujihang/p/7413906.html
安装readline-sync,Node.js的环境我就不多介绍了想必大佬们都清楚得很。没错,这样如果用来写一个cli工具相当的好用,可是现在的需求不同,我们需要的是复制到答题框可以直接运行的代码,现在神器就该出现了。
npm install readline-sync
绝望的时候还是GitHub靠得住,只需两步即可实现read_line方法:
var __readline = require('readline-sync')
__readline.setDefaultOptions({prompt: ''})
var read_line = __readline.prompt
这样子就可以了
var __readline = require('readline-sync');
__readline.setDefaultOptions({prompt: ''});
const read_line = __readline.prompt;
const {log}=console;
const print=log;
var line;
var solveMeFirst = (a,b) => a+b;
while((line = read_line()) != ''){
let arr = line.split(' ');
let a = parseInt(arr[0]);
let b = parseInt(arr[1]);
let c = solveMeFirst(a, b);
print(c);
}