Study/Algorithm
[programmers / JavaScript] 햄버거 만들기
https://school.programmers.co.kr/learn/courses/30/lessons/133502 // test const ingredient = [2, 1, 1, 2, 3, 1, 2, 3, 1]; sol 1 function solution(ingredient) { let count = 0; let stack = []; for (let i = 0; i = 4) { const hamburger = stack.slice(-4).join(""); if (hamburger === "1231") { console.log(hamburger); stack.splice(-..
[BEAKJOON / node.js] 26069 붙임성 좋은 총총이
https://www.acmicpc.net/problem/26069 // test.txt 12 bnb2011 chansol chansol chogahui05 chogahui05 jthis jthis ChongChong jthis jyheo98 jyheo98 lms0806 lms0806 pichulia pichulia pjshwa pjshwa r4pidstart r4pidstart swoon swoon tony9402 tony9402 bnb2011 Sol 1 const [N, ...input] = require("fs") .readFileSync("test.txt") .toString() .trim() .split("\n"); let arr = input.map((v) => v.split(" ")); le..
[programmers / JavaScript] 연속된 수의 합
https://school.programmers.co.kr/learn/courses/30/lessons/120923 //test const num = 3; const total = 12; sol1 function solution(num, total) { let answer = []; let ceilNum = Math.ceil(total / 2); while (true) { for (let i = num; i > 0; i--) { answer.push(ceilNum - i); } let sum = answer.reduce((acc, cur) => acc + cur, 0); if (sum === total) break; else if (sum < total) ceilNum++; else ceilNum--; ..
[BEAKJOON / node.js] 16120 PPAP
https://www.acmicpc.net/problem/16120 // test.txt 'PPAPPAP' sol1 let P = require('fs').readFileSync('test.txt').toString().trim().split(''); function solution(P) { let stack = []; for(let i=0;i= 4) { if(stack[stack.length-1] === 'P') { if(stack.slice(-4).join('') === 'PPAP') { stack.splice(-4); stack.push('P'); } } } } return stack.length === 1 && stack[stack.length-1] === 'P' ? 'PPAP' : 'NP' } ..
[BEAKJOON / node.js] 11509 풍선 맞추기
https://www.acmicpc.net/problem/11509 // test.txt 5 4 5 2 1 4 sol1 - 시간 초과❌ let [N,...input] = require('fs').readFileSync('test.txt').toString().trim().split('\n'); function solution(N,input) { let arr = input[0].split(' ').map(Number); let answer = 0; while(Math.max(...arr) !== 0) { let top = Math.max(...arr); let topIndex = arr.indexOf(top); for(let i=topIndex+1;i0); let answer = 0; for(let i ..
[BEAKJOON / node.js] 1946 신입 사원
https://www.acmicpc.net/problem/1946 // test.txt 3 5 3 2 1 4 4 1 2 3 5 5 7 3 6 7 3 4 2 1 4 5 7 2 5 6 1 5 1 5 2 4 3 3 4 2 5 1 sol1 - ❌ const [T,...input] = require('fs').readFileSync('test.txt').toString().trim().split('\n'); for(let i=0;iv.split(' ').map(Number)).sort((a,b) => a[0]-b[0]); let answer = 1; for(let i=1;i
[BEAKJOON / node.js] 1475 방 번호
https://www.acmicpc.net/problem/1475 //test.txt 12696 sol1 let input = require('fs').readFileSync('test.txt').toString().trim(); function solution(input) { let arr = Array.from({length:10},()=>0); for(let i=0;i
[programmers / JavaScript] 큰 수 만들기
https://programmers.co.kr/learn/courses/30/lessons/42883# const number = "4177252841"; const k = 4; sol1 function solution(number, k) { let stack = []; for(let i=0;i0 && stack[stack.length-1]