๋ฐ์ํ ๐ ์๊ณ ๋ฆฌ์ฆ/๋ฐฑ์ค JS21 [๋ฐฑ์ค] node.js/ 2606_๋ฐ์ด๋ฌ์ค ์ด๋ฒ ๋ฌธ์ ๋ ์ฝ์ง ์์๋ค. dfs๋ฅผ ์ด์ฉํด ํ์ดํ๋ ๋ฌธ์ ์๊ณ , ๋๋ dfs์ ์์ง ์ฝํ๊ธฐ ๋๋ฌธ์ ๋ ๋ง์ด ๊ณต๋ถํด์ผ ํ๋คใ . ์ ๋ต ํ์ด n+1์ ํ๋ ์ด์ ๋ ์ธ๋ฑ์ค์ ์๋ฅผ ๋ง์ถฐ์ฃผ๊ธฐ ์ํด์! ( 0 idx์ ๊ฐ์ ์ฐ์ง ์๋๋ค๊ณ ๋ณด๋ฉด ๋๋ค.) const fs = require('fs'); let input = (fs.readFileSync('./dev/stdin') + '').toString().trim().split('\n'); let n = Number(input.shift()); let m = Number(input.shift()); let graph = [...new Array(n + 1)].map(() => []); let visited = new Array(n + 1).fill(false); let.. 2021. 11. 7. [๋ฐฑ์ค] node.js/ 1463_1๋ก ๋ง๋ค๊ธฐ ๋ฌธ์ ๋ฅผ ๋ณด์๋ง์ ๋๋์ด ์๋ค. ์ ์ด๊ฑฐ.. ์๊ณ ๋ฆฌ์ฆ์ด ํ์ํ๋ค!!!!! ์ฒ์์๋ 3๋ถํฐ ๋๋๊ณ , 2๋ถํฐ๋๋๊ณ -1 ํ๋ฉด ๋์ง ๋ผ๊ณ ์๊ฐํ๋๋ฐ ์ฒ๋ง์ ๋ง์~ ํํธ์ ๋กํ๋ ๋์ ์๋ ๊ฐ๋ฅด์นจ์ ๋ณด๊ณ ๋ฐ๋ก ๋๋ ธ๋ค. ์ฐธ๊ณ ํ์ด const fs = require('fs'); let n = (fs.readFileSync('./dev/stdin') + '').toString().trim(); n = Number(n); const DP = new Array(n + 1).fill(0); for (let i = 2; i 2021. 10. 27. ๋ฐฑ์ค] node.js/ 1448_ ์ผ๊ฐํ ๋ง๋ค๊ธฐ ๋ด ํ์ด (์๊ฐ์ด๊ณผ) const fs = require('fs'); let input = (fs.readFileSync('./dev/stdin') + '').toString().trim().split('\n'); const n = +input.shift(); let sumArr = []; input = input.map((line) => parseInt(line)); input.sort((a, b) => parseInt(b) - parseInt(a)); const checkTri = (a, b, c) => { return a < b + c; }; for (let i = 0; i < n - 2; i++) { if (checkTri(input[i], input[i + 1], input[i + 2])) { a.. 2021. 10. 23. [๋ฐฑ์ค] node.js/ 1748_ ์ ์ด์ด์ฐ๊ธฐ(1) ๋ดํ์ด const fs = require('fs'); let input = (fs.readFileSync('./dev/stdin') + '').toString().trim(); const lenInput = input.length; let cnt = 0; // 1 2 3 // 10-1 100-10 + 120-(100-1) for (let i = 1; i 2021. 10. 22. [๋ฐฑ์ค] node.js/ 15650 N๊ณผM(2) ๋ด ํ์ด const fs = require('fs'); let [n, m] = (fs.readFileSync('./dev/stdin') + '').toString().trim().split(' '); let visit = new Array(parseInt(n)).fill(false); n = parseInt(n); m = parseInt(m); let ans = []; const back = (d, n, m, idx) => { if (d === m) { console.log(...ans); return; } for (let i = idx; i < n; i++) { if (visit[i]) continue; visit[i] = true; ans.push(i + 1); back(d + 1, n, m, i);.. 2021. 10. 21. [๋ฐฑ์ค] node.js/ 15649 N๊ณผ M 1 ๋ด ํ์ด const fs = require('fs'); let [n, m] = (fs.readFileSync('./dev/stdin') + '').toString().trim().split(' '); let ans = []; let visit = new Array(parseInt(n)).fill(false); const back = (d, n, m) => { // m๊ฐ์ ์์๊น์ง ์ฐผ๋์ง ํ์ธ if (d === m) { console.log(...ans); return; } for (let i = 0; i < n; i++) { if (!visit[i]) { visit[i] = true; ans.push(i + 1); back(d + 1, n, m); ans.pop(); visit[i] = false; } .. 2021. 10. 20. [๋ฐฑ์ค] node.js/ 1302 ๋ฒ ์คํธ์ ๋ฌ ๋ด ํ์ด (์ ๋ต) const fs = require('fs'); let input = (fs.readFileSync('./dev/stdin') + '').toString().trim().split('\n'); input.shift(); let bookDict = {}; input.map((book) => { if (!bookDict[book]) bookDict[book] = 1; else bookDict[book] += 1; }); const sortBook = Object.entries(bookDict) .sort(([aa, a], [bb, b]) => { if (a === b) { return aa < bb ? -1 : aa == bb ? 0 : 1; } return b - a; }) .reduce(.. 2021. 10. 19. [๋ฐฑ์ค] node.js/ 10866 ๋ฑ ๋ด ํ์ด const fs = require('fs'); let input = (fs.readFileSync('./dev/stdin') + '').toString().trim().split('\n'); input.shift(); let queue = []; const cmdObj = { push_back: (x) => { queue.push(x); return ''; }, push_front: (x) => { queue.unshift(x); return ''; }, pop_front: () => queue.shift() || -1, pop_back: () => queue.pop() || -1, size: () => queue.length, empty: () => (queue[0] ? 0 : 1), fron.. 2021. 10. 18. [๋ฐฑ์ค] node.js/ 10828 ์คํ ์ฒ์ ํ์ด(์๊ฐ์ด๊ณผ) const fs = require('fs'); let input = (fs.readFileSync('./test') + '').toString().trim().split('\n'); input.shift(); let stack = []; input.map((cmd) => { const cmdArr = cmd.split(' '); const command = cmdArr[0]; switch (command) { case 'push': const number = cmdArr[1]; stack.push(parseInt(number)); break; case 'top': if (stack.length === 0) console.log(-1); else console.log(stack[sta.. 2021. 10. 15. ์ด์ 1 2 3 ๋ค์ ๋ฐ์ํ