알고리즘/백준
[boj 10866] 덱 -js
// 덱 const filePath = process.platform === "linux" ? "/dev/stdin" : "input.txt"; const input = require('fs').readFileSync(filePath).toString().trim().split(/\s/); const N = input.shift(); const sol = (N,input) =>{ const deque = []; const result = []; while(input.length){ const command = input.shift(); if(command === 'push_front'){ deque.unshift(input.shift()); } else if (command === 'push_back')..
[boj 1158] 요세푸스 문제 -js
// 요세푸스 문제 const filePath = process.platform === "linux" ? "/dev/stdin" : "input.txt"; const input = require('fs').readFileSync(filePath).toString().trim().split(/\s/).map(Number); const N = input.shift(); const K = input.shift(); const sol = (N,K) =>{ const arr = new Array(N); const result =[]; for(let i =1; i
![[boj 1406] 에디터 - js](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FxRvVp%2FbtrvoA6nNMl%2FjyJN7cZRXzkM1SPK3syEDK%2Fimg.png)
[boj 1406] 에디터 - js
문제 한 줄로 된 간단한 에디터를 구현하려고 한다. 이 편집기는 영어 소문자만을 기록할 수 있는 편집기로, 최대 600,000글자까지 입력할 수 있다. 이 편집기에는 '커서'라는 것이 있는데, 커서는 문장의 맨 앞(첫 번째 문자의 왼쪽), 문장의 맨 뒤(마지막 문자의 오른쪽), 또는 문장 중간 임의의 곳(모든 연속된 두 문자 사이)에 위치할 수 있다. 즉 길이가 L인 문자열이 현재 편집기에 입력되어 있으면, 커서가 위치할 수 있는 곳은 L+1가지 경우가 있다. 이 편집기가 지원하는 명령어는 다음과 같다. 초기에 편집기에 입력되어 있는 문자열이 주어지고, 그 이후 입력한 명령어가 차례로 주어졌을 때, 모든 명령어를 수행하고 난 후 편집기에 입력되어 있는 문자열을 구하는 프로그램을 작성하시오. 단, 명령어가..
[boj 9012] 괄호 - js
문제 괄호 문자열(Parenthesis String, PS)은 두 개의 괄호 기호인 ‘(’ 와 ‘)’ 만으로 구성되어 있는 문자열이다. 그 중에서 괄호의 모양이 바르게 구성된 문자열을 올바른 괄호 문자열(Valid PS, VPS)이라고 부른다. 한 쌍의 괄호 기호로 된 “( )” 문자열은 기본 VPS 이라고 부른다. 만일 x 가 VPS 라면 이것을 하나의 괄호에 넣은 새로운 문자열 “(x)”도 VPS 가 된다. 그리고 두 VPS x 와 y를 접합(concatenation)시킨 새로운 문자열 xy도 VPS 가 된다. 예를 들어 “(())()”와 “((()))” 는 VPS 이지만 “(()(”, “(())()))” , 그리고 “(()” 는 모두 VPS 가 아닌 문자열이다. 여러분은 입력으로 주어진 괄호 문자열..
[boj 9093] 단어 뒤집기 - js
// 단어 뒤집기 const filePath = process.platform === "linux" ? "/dev/stdin" : "input.txt"; const input = require('fs').readFileSync(filePath).toString().trim().split('\n'); const T = input.shift(); const sol = (input) =>{ const result = []; for(let i =0; i