0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paizaラーニング レベルアップ問題集 スタック・キューメニュー応用編 JavaScript 3 つのキュー

Posted at

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"));
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?