I want to write NodeJS code for solving problems like ICPC. The following is an example using a template of www.hackerrank.com for submitting in JavaScript:
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
/////////////// ignore above this line ////////////////////
function main() {
var s = readLine();
s = s.split(",");
s = s.join(" ");
process.stdout.write(s);
}
I want to code offline, so I need to run the programs in my Windows console. For runnig the srcript using C:users\user>node path\file.js I added at the end of the code the line
main();
and the scripts runs, but it doesn't process the standard input. It gives me and error in "s=s.split()", the error is the following "TypeError: Cannot read property 'split' of undefined". If anyone know how to do node process the standard input please help me.