概要
atcoderで標準入力に対応した時の話
対象者
- windowsでやっている
コード
type a.txt | node a.js
で実行します。
パイプを使わないと、end
イベントが発生しません。
process.stdin.resume();
process.stdin.setEncoding('utf8');
var g_input = '';
process.stdin.on('data', function(chunk) {
g_input += chunk;
});
process.stdin.on('end', function() {
main(g_input.split(/\r?\n/));
});
function main(inputs){
// todo
}
備考
windowではない場合は、次が簡単です。
var stdin = require("fs").readFileSync("/dev/stdin", "utf8");