본문 바로가기

728x90

JavaScript

[NodeJS] 백준 1874 /** * @link https://www.acmicpc.net/problem/1874 */ const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const input = []; rl.on('line', (line) => { input.push(Number(line)); }).on('close', () => { const [n, ...arr] = input; solution(n, arr); process.exit(); }); /** * * @param {number} n * @param {number[]} sequence // 수열 *.. 더보기
[NodeJS] 백준 2920 /** * @link https://www.acmicpc.net/problem/2920 */ const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const input = []; rl.on('line', (line) => { input.push(line); }).on('close', () => { const result = solution(input[0]); console.log(result); process.exit(); }); function solution(str) { if (str === '1 2 3 4 5 6 7 8') { r.. 더보기
[NodeJS] 백준 2475 /** * @link https://www.acmicpc.net/problem/2475 */ const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const input = []; rl.on('line', (line) => { input.push(line); }).on('close', () => { const result = solution(input[0]); console.log(result); process.exit(); }); /** * * @param {string} str */ function solution(str) { con.. 더보기
[NodeJS] 백준 1654 /** * @link https://www.acmicpc.net/problem/1654 */ const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const input = []; rl.on('line', (line) => { input.push(line); }).on('close', () => { const [str1, ...str2] = input; const [n, k] = str1.split(' ').map(Number); const arr = str2.map(Number).sort((a, b) => a - b); const re.. 더보기
[NodeJS] 프로그래머스 이진 변환 반복하기 const convertBinaryString = (num) => { const arr = []; while (0 { let removeZeroCnt = 0; let tryCnt = 0; while (s !== '1') { tryCnt++; const prevLen = s.length; const oneCnt = [...s].filter((v) => v === '1').length; removeZeroCnt += prevLen - oneCnt; s = convertBinarySt.. 더보기
[NodeJS] 프로그래머스 전력망을 둘로 나누기 const solution = (n, wires) => { let answer = 999; const map = {}; const getCnt = (node, exceptionNode) => { let cnt = 0; const queue = [node]; const set = new Set(); set.add(node); set.add(exceptionNode); while (queue.length) { const curNode = queue.pop(); cnt++; for (const n of map[curNode]) { if (!set.has(n)) { set.add(n); queue.push(n); } } } return cnt; }; for (const w of wires) { const [v1.. 더보기
[NodeJS] 프로그래머스 양궁대회 const solution = (n, info) => { const infoLen = info.length; let answer = new Array(infoLen).fill(0); let diff = 0; const recursive = (num, idx, arr) => { if (num === 0) { // 화살을 다 소모 했을경우 let apeach = 0; // 어피치 점수 let ryan = 0; // 라이언 점수 // 점수 계산 for (let i = 0; i < infoLen; i++) { const ap = info[i]; const ry = arr[i]; if (ap < ry) { ryan += 10 - i; } else if (ry < ap) { apeach += 10 - i; } } .. 더보기
[NodeJS] 프로그래머스 입국 심사 const solution = (n, times) => { // 이분탐색을 위해 오름차순 정렬 times.sort((a, b) => a - b); let left = 1; let right = n * times[times.length - 1]; let answer = right; // 최댓값 while (left { // 한 사람당 몇명 할 수 있는지 cnt += Math.floor(mid / v); if (n 더보기

728x90