일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 프로그래머스 레벨 2
- dfs
- typescript
- 소켓
- 타입 챌린지
- dp
- Algorithm
- 프로그래머스
- type challenge
- Node.js
- javascript
- 타입스크립트
- ip
- 수학
- 알고리즘
- 문자열
- Nestjs
- TCP
- 크롤링
- HTTP
- 레벨 1
- 백준
- Crawling
- 가천대
- 자바스크립트
- BFS
- 쉬운 문제
- 그래프
- HTTP 완벽 가이드
- socket
- Today
- Total
목록Node.js (167)
kakasoo
const readline = require("readline"); rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let cnt = 0; let count = 0; let clothes = 0; input = []; rl.on("line", (line) => { if (!count) { count = Number(line); } else { if (!isNaN(line - 0)) { clothes = Number(line); cnt++; if (clothes === 0) { console.log(0); } } else { input.push(line); if (input.length === clothes)..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count = 0; rl.on("line", (line) => { if (!count) { count = Number(line); } else { main(line); rl.close(); } }).on("close", () => process.exit()); /** * * @param {string} line */ const main = (line) => { const numbers = line.split(" ").map(Number); const DP1 = [numbers..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count = 0; rl.on("line", (line) => { if (!count) { count = Number(line); } else { main(line); } }); /** * * @param {string} line */ const main = (line) => { const numbers = line.split(" ").map(Number); const DP = new Array(numbers.length).fill(0); for (let i = 0; i < ..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { main(Number(line)); rl.close(); }).on("close", () => { process.exit(); }); /** * * @param {number} line */ const main = (line) => { const DP = new Array(line + 1).fill(0); DP[2] = 3; for (let i = 4; i
이전 부분 수열 문제들처럼 풀되 조건만 바꿔주면 된다. 그런데 나는 틀렸었는데, 그 이유는 DP[i]의 값을 1로 초기화했기 때문이다. 이전 문제들은 개수를 세는 것이기 때문에 전부 1로 시작했겠지만, 이건 합산하는 것이기 때문에 각 DP[i]는 자기 차례의 숫자가 초깃값으로 저장되어야 한다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.output, }); let count = 0; rl.on("line", (line) => { if (!count) { count = Number(line); } else { main(line); rl.close(..
이전 문제는 결국 다른 사람의 코드를 참고했지만, 이 문제를 풀 때는 어제의 기억으로 그냥 풀 수 있었다. 사실 어제 문제랑 똑같다. 다른 점이 있다면 감소한다는 부분인데, 자바스크립트에서는 reverse라는 내장 함수가 있기 때문에 그냥 거꾸로 돌린 후에 똑같이 풀어주면 된다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.output, }); let count = 0; rl.on("line", (line) => { if (!count) { count = Number(line); } else { main(line); rl.close(); } })...
나는 이걸 틀려서, 결국 다른 사람의 코드를 참고했었다. 유명한 알고리즘이라 별도의 이름도 있다고 한다. LIS 라고 하는데, 말 그대로 Longest Increase Sequence? 뭐 그런 이름이었던 거 같다. 나는 이걸 짜기 위해서 n이 증가함에 따라 이전에 가능했던 수열에 새 값을 붙인 경우, 붙이지 않은 경우를 탐색했는데, 메모리 초과가 심각해서 풀 수가 없었다. DP는 DP 방법 말고는 답이 없는 듯 하다. 다음 문제가 가장 긴 감소하는 부분 수열인데,코드를 전혀 보지 않고 풀어보도록 하자. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process..
처음에는 대괄호, 소괄호를 따로 따로 배열을 만들어서 관리해 주었는데, 예외가 있었다. [(]) 형태로 들어올 때 제대로 동작하지 않았다. 그래서 배열을 하나로 합쳐줬더니 해결되었다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line", (line) => { if (line === ".") { rl.close(); } main(line); }).on("close", () => { process.exit(); }); /** * * @param {string} line */ const main = (line) =>..
부분 문자열, 부분 수열과 같다고 생각하면 되겠다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count = 0; const input = []; rl.on("line", (line) => { if (!count) { count = Number(line); } else { input.push(line); if (input.length === count) { main(line); rl.close(); } } }).on("close", () => { process.exit(); }); const factorial = (n..
그렇게 어려운 문제는 아니었다. 그냥 마이너스를 할 때, 최대한 크게 마이너스를 해주면 된다. 그래서 마이너스가 나오면 마이너스 뒤로 있는 모든 플러스를 우선시해줘서 빼야할 값을 크게 바꿔주면 된다. 그래서 -를 기준으로 문자열을 split 해주고, 각 요소들을 전부 더 해준다. 예를 들어 43 - 43 + 45 - 45가 라는 문자열이 있으면 ( 띄어쓰기는 원래 없어야 한다. ) 43,48,45 라는 숫자 배열로 바꿔주고, 앞에서부터 차례대로 빼주면 된다. const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); rl.on("line",..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let count = 0; const input = [0]; rl.on("line", (line) => { if (!count) { count = Number(line); } else { input.push(Number(line)); if (input.length === count + 1) { main(); rl.close(); } } }).on("close", () => { process.exit(); }); const main = () => { const DP = new Arra..
const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); let COUNT; let MAX_WEIGHT; let weights = [0]; let values = [0]; rl.on("line", (line) => { const arr = line.split(" ").map(Number); if (!COUNT && !MAX_WEIGHT) { COUNT = arr[0]; MAX_WEIGHT = arr[1]; } else { weights.push(arr[0]); values.push(arr[1]); if (weights.length > CO..