1406. 에디터 - node.js / javascript

문제

내 코드

let fs = require("fs");
let input = fs.readFileSync("/dev/stdin").toString().trim().split("\n");

const leftStack = input[0].split("");
const rightStack = [];
const M = Number(input[1]);

for (let i = 2; i < M + 2; i++) {
  const [order, newWord] = input[i].split(" ");

  if (order === "L" && leftStack.length) {
    rightStack.push(leftStack.pop());
  } else if (order === "D" && rightStack.length) {
    leftStack.push(rightStack.pop());
  } else if (order === "B") {
    leftStack.pop();
  } else if (order === "P") {
    leftStack.push(newWord);
  }
}

let answer = leftStack.join("");
answer += rightStack.reverse().join("");
console.log(answer);

깃허브 링크

https://github.com/highjoon/JS_Algorithm/blob/master/BOJ/%EC%8A%A4%ED%83%9D/1406.js

좋은 웹페이지 즐겨찾기