Training/Problem Solving

[JS] μ½˜μ†”λ‘œ μž…λ ₯ λ°›κΈ°

FATKITTY 2022. 4. 6. 00:29
λ°˜μ‘ν˜•

πŸ”† readline 

const readline = require("readline");
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
rl.on("line", (line) => {
  // ν•œ 쀄씩 μž…λ ₯받은 ν›„ μ‹€ν–‰ν•  μ½”λ“œ
  rl.close(); // ν•„μˆ˜. μ—†μœΌλ©΄ μž…λ ₯을 λ¬΄ν•œνžˆ λ°›λŠ”λ‹€
});
rl.on("close", () => {
  process.exit(); // μž…λ ₯이 λλ‚œ ν›„ μ‹€ν–‰ν•  μ½”λ“œ
});

 

 

πŸ”† (node.js) fs - λ°±μ€€ μ‹œκ°„μ œν•œ ζœ‰ λ¬Έμ œν’€μ΄μš© 

// ν•œ 쀄 μž…λ ₯
let input = require("fs").readFileSync("/dev/stdin").toString();

// μ—¬λŸ¬ 쀄 μž…λ ₯
let input = require("fs").readFileSync("/dev/stdin").toString().split("\n");
λ°˜μ‘ν˜•