๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
[๋ฐฑ์ค€][Node.js] 9095๋ฒˆ : 1, 2, 3 ๋”ํ•˜๊ธฐ Algorithm - 1, 2, 3 ๋”ํ•˜๊ธฐ - ๋ฌธ์ œ ์ •์ˆ˜ 4๋ฅผ 1, 2, 3์˜ ํ•ฉ์œผ๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฐฉ๋ฒ•์€ ์ด 7๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค. ํ•ฉ์„ ๋‚˜ํƒ€๋‚ผ ๋•Œ๋Š” ์ˆ˜๋ฅผ 1๊ฐœ ์ด์ƒ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค. 1+1+1+1 1+1+2 1+2+1 2+1+1 2+2 1+3 3+1 ์ •์ˆ˜ n์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, n์„ 1, 2, 3์˜ ํ•ฉ์œผ๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฐฉ๋ฒ•์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…์ถœ๋ ฅ ์˜ˆ์‹œ ๋ฌธ์ œ ํ’€๊ธฐ const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let input = []; rl.on("line", function (line) { input.push(line.to.. 2021. 12. 21.
[๋ฐฑ์ค€][Node.js] 9093๋ฒˆ : ๋‹จ์–ด ๋’ค์ง‘๊ธฐ Algorithm - ๋‹จ์–ด ๋’ค์ง‘๊ธฐ - ๋ฌธ์ œ ๋ฌธ์žฅ์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ๋‹จ์–ด๋ฅผ ๋ชจ๋‘ ๋’ค์ง‘์–ด์„œ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๋‹จ, ๋‹จ์–ด์˜ ์ˆœ์„œ๋Š” ๋ฐ”๊ฟ€ ์ˆ˜ ์—†๋‹ค. ๋‹จ์–ด๋Š” ์˜์–ด ์•ŒํŒŒ๋ฒณ์œผ๋กœ๋งŒ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ์‹œ ๋ฌธ์ œ ํ’€๊ธฐ let fs = require("fs"); let input = fs.readFileSync("/dev/stdin").toString().split("\n"); input.shift(); for (let i = 0; i el.split('')); let newStr = []; for (let j = 0; j < str.length; j++) { newStr.push.. 2021. 12. 21.
[๋ฐฑ์ค€][Node.js] 9086๋ฒˆ : ๋ฌธ์ž์—ด Algorithm - ๋ฌธ์ž์—ด - ๋ฌธ์ œ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅ์œผ๋กœ ์ฃผ๋ฉด ๋ฌธ์ž์—ด์˜ ์ฒซ ๊ธ€์ž์™€ ๋งˆ์ง€๋ง‰ ๊ธ€์ž๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…์ถœ๋ ฅ ์˜ˆ์‹œ ๋ฌธ์ œ ํ’€๊ธฐ let fs = require("fs"); let input = fs.readFileSync("/dev/stdin").toString().split("\n"); for (let i = 1; i 2021. 12. 19.
[๋ฐฑ์ค€][Node.js] 9085๋ฒˆ : ๋”ํ•˜๊ธฐ Algorithm - ๋”ํ•˜๊ธฐ - ๋ฌธ์ œ 10๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ž์—ฐ์ˆ˜ N๊ฐœ๋ฅผ ์ฃผ๋ฉด ํ•ฉ์„ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…์ถœ๋ ฅ ์˜ˆ์‹œ ๋ฌธ์ œ ํ’€๊ธฐ let fs = require("fs"); let input = fs.readFileSync("/dev/stdin") .toString() .split("\n"); input.shift(); let result = []; for (let i = 1; i Number(el)); result.push(arr.reduce((past, curr) => past + curr, 0)); } console.log(result.join('\n')); 2021. 12. 18.
[๋ฐฑ์ค€][Node.js] 9076๋ฒˆ : ์ ์ˆ˜ ์ง‘๊ณ„ Algorithm - ์ ์ˆ˜ ์ง‘๊ณ„ - ๋ฌธ์ œ ํ•œ๊ตญ ์ฒด์กฐํ˜‘ํšŒ์—์„œ๋Š” ์‹ฌํŒ์˜ ์˜ค์‹ฌ์„ ๋ง‰๊ธฐ ์œ„ํ•˜์—ฌ ์ ์ˆ˜ ์ง‘๊ณ„ ์‹œ์Šคํ…œ์„ ๊ณ ์น˜๊ธฐ๋กœ ํ•˜์˜€๋‹ค. ์ด์ „์—๋Š” 5๋ช…์˜ ์‹ฌํŒ์ด 1์ ๋ถ€ํ„ฐ 10์ ๊นŒ์ง€ ์ •์ˆ˜์˜ ์ ์ˆ˜๋ฅผ ์ฃผ๋ฉด ์ตœ๊ณ ์ ๊ณผ ์ตœ์ €์ ์„ ํ•˜๋‚˜์”ฉ ์ œ์™ธํ•œ ์ ์ˆ˜์˜ ํ•ฉ์„ ์ด์ ์œผ๋กœ ํ•˜์˜€๋‹ค. ์ด๋ฅผ ๋ณด์™„ํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ตœ๊ณ ์ ๊ณผ ์ตœ์ €์ ์„ ๋บ€ ๋‚˜๋จธ์ง€ 3๋ช… ์ ์ˆ˜์˜ ์ตœ๊ณ ์ ๊ณผ ์ตœ์ €์ ์˜ ์ฐจ์ด๊ฐ€ 4์  ์ด์ƒ ๋‚˜๊ฒŒ ๋˜๋ฉด ์ ์ˆ˜ ์กฐ์ •์„ ๊ฑฐ์ณ์„œ ๋‹ค์‹œ ์ ์ˆ˜๋ฅผ ๋งค๊ธฐ๋ ค๊ณ  ํ•œ๋‹ค. ์ ์ˆ˜๋ฅผ ์ง‘๊ณ„ํ•˜์—ฌ ์ด์ ์„ ๊ณ„์‚ฐํ•˜๊ฑฐ๋‚˜, ์ ์ˆ˜ ์กฐ์ •์„ ๊ฑฐ์ณ์„œ ๋‹ค์‹œ ์ ์ˆ˜๋ฅผ ๋งค๊ธฐ๋ ค๊ณ  ํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ์ด์  ๋Œ€์‹  KIN(Keep In Negotiation)์„ ์ถœ๋ ฅํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ์ž…์ถœ๋ ฅ ์˜ˆ์‹œ ๋ฌธ์ œ ํ’€๊ธฐ const readline = require("readline"); const rl = readlin.. 2021. 12. 17.
[๋ฐฑ์ค€][Node.js] 9012๋ฒˆ : ๊ด„ํ˜ธ Algorithm - ๊ด„ํ˜ธ - ๋ฌธ์ œ ๊ด„ํ˜ธ ๋ฌธ์ž์—ด(Parenthesis String, PS)์€ ๋‘ ๊ฐœ์˜ ๊ด„ํ˜ธ ๊ธฐํ˜ธ์ธ ‘(’ ์™€ ‘)’ ๋งŒ์œผ๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋Š” ๋ฌธ์ž์—ด์ด๋‹ค. ๊ทธ ์ค‘์—์„œ ๊ด„ํ˜ธ์˜ ๋ชจ์–‘์ด ๋ฐ”๋ฅด๊ฒŒ ๊ตฌ์„ฑ๋œ ๋ฌธ์ž์—ด์„ ์˜ฌ๋ฐ”๋ฅธ ๊ด„ํ˜ธ ๋ฌธ์ž์—ด(Valid PS, VPS)์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. ํ•œ ์Œ์˜ ๊ด„ํ˜ธ ๊ธฐํ˜ธ๋กœ ๋œ “( )” ๋ฌธ์ž์—ด์€ ๊ธฐ๋ณธ VPS ์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. ๋งŒ์ผ x ๊ฐ€ VPS ๋ผ๋ฉด ์ด๊ฒƒ์„ ํ•˜๋‚˜์˜ ๊ด„ํ˜ธ์— ๋„ฃ์€ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด “(x)”๋„ VPS ๊ฐ€ ๋œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋‘ VPS x ์™€ y๋ฅผ ์ ‘ํ•ฉ(concatenation)์‹œํ‚จ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด xy๋„ VPS ๊ฐ€ ๋œ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด “(())()”์™€ “((()))” ๋Š” VPS ์ด์ง€๋งŒ “(()(”, “(())()))” , ๊ทธ๋ฆฌ๊ณ  “(()” ๋Š” ๋ชจ๋‘ VPS ๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž์—ด์ด๋‹ค. ์—ฌ๋Ÿฌ๋ถ„.. 2021. 12. 16.