๐จ ์ฐธ๊ณ ์ฝ๋
์ฝ๋
const fs = require('fs');
const input = fs.readFileSync('/dev/stdin').toString().trim().split("\n");
const init = input.shift().split("");
const M = +input.shift();
const leftStack = [...init];
const rightStack = [];
for (let i = 0; i < M; i++) {
const command = input[i].split(" ");
if (command[0] === "L") {
if(leftStack.length) rightStack.push(leftStack.pop());
} else if (command[0] === "D") {
if(rightStack.length) leftStack.push(rightStack.pop());
} else if (command[0] === "B") {
leftStack.pop();
} else {
leftStack.push(command[1]);
}
}
rightStack.reverse();
console.log([...leftStack, ...rightStack].join(""));