3 つのキュー (paizaランク C 相当)
解答例
問題文に沿って実装します。
const fs = require("fs");
const input = fs.readFileSync("/dev/stdin", "utf-8").trim();
const lines = input.split("\n");
const [N] = lines[0].split(" ").map(Number);
let [queue1, queue2, queue3] = [[], [], []];
for (let i = 1; i <= N; i++) {
const Q = lines[i].split(" ").map((v, i) => i === 0 ? v : Number(v));
if (Q[0] === "push") {
const [_, S, X] = Q;
if (S === 1) {
queue1.push(X);
} else if (S === 2) {
queue2.push(X);
} else {
queue3.push(X);
}
} else {
const [_, S] = Q;
if (S === 1) {
queue1.shift();
} else if (S === 2) {
queue2.shift();
} else {
queue3.shift();
}
}
}
if(queue1.length > 0) console.log(queue1.join("\n"));
if(queue2.length > 0) console.log(queue2.join("\n"));
if(queue3.length > 0) console.log(queue3.join("\n"));