본문 바로가기
SMALL

javascript16

백준 Node.js(자바스크립트) 2869번 달팽이올라가는 문제 문제는 그렇게 어렵지않으나 단순하게 for,while을 사용하면 시간초과 //이 방식은 시간초과 const fs = require('fs'); const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; let input = fs.readFileSync(filePath).toString().split(' '); const A = +input[0]; const B = +input[1]; const V = +input[2]; solution(); function solution() { let climb = 0; let i = 0; while(climb = V) { con.. 2021. 8. 29.
백준 Node.js(자바스크립트) 1712번 손익분기점 문제 포문으로 해보니 시간초과가 나왔다. const fs = require('fs'); const filePath = process.platform === 'linux' ? '/dev/stdin' : './input.txt'; let input = fs.readFileSync(filePath).toString().split(' '); const A = +input[0]; const B = +input[1]; const C = +input[2]; console.log("ABC is",A, B, C); solution(A,B,C); function solution(A,B,C) { let answer = 1; for (let i = 1; i < 2100000001; i++) { if ((A + B * i) - C .. 2021. 8. 20.
Node.js로 백준문제풀기 런타임에러(runtime error) 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' :.. 2021. 8. 6.
백준 Node.js(자바스크립트) 2941번 크로아티아 알파벳 문제 풀이 const fs = require("fs"); const input = ( process.platform === "linux" ? fs.readFileSync("/dev/stdin").toString() : `ljes=njak` ).trim(); let croatia = ["c=", "c-", "dz=", "d-", "lj", "nj", "s=", "z="]; function solution(input) { for (let alphabet of croatia) { input = input.split(alphabet).join("Q"); } return input.length; // return input일 경우 QeQQak를 반환한다. } console.log(solution(input)); con.. 2021. 8. 5.
LIST