본문 바로가기
코테/코테withJS

Node.js로 백준문제풀기 런타임에러(runtime error)

by 트레일헤드레인저 2021. 8. 6.
SMALL

Node.js, 즉 자바스크립트로 백준문제풀이를 하려면 해야하는 단계가 있다.

처음에는 어렵게 느껴질 수 있지만 하다보면 그냥 복붙하게된다

 

let fs = require('fs');
let input = fs.readFileSync('/dev/stdin');


//또는

let input = require('fs').readFileSync('/dev/stdin');

//물론 여기에 toString() 이나 split() 등등을 붙여서 한다.

저렇게하면 백준에서 입력받는 값을 갖고 진행할 수 있다.

 

vscode에서 text를 만들어서 예제를 넣고 거기에

const fs = require('fs');
const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt';
const input = fs.readFileSync(filePath).toString().split('\n');

이런식으로 넣으면 vscode에서 확인하면서 하는게 가능하다.

LIST