結果

問題 No.714 回転寿司屋のシミュレート
ユーザー Rim_EarthLightsRim_EarthLights
提出日時 2023-05-10 17:41:07
言語 TypeScript
(5.4.3)
結果
WA  
実行時間 -
コード長 1,683 bytes
コンパイル時間 8,789 ms
コンパイル使用メモリ 252,996 KB
実行使用メモリ 52,640 KB
最終ジャッジ日時 2023-08-17 21:48:51
合計ジャッジ時間 16,449 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

"use strict";
import { readFileSync } from "fs";

let Users: User[] = [];

const main = (arg: string) => {
  const input = arg
    .trim()
    .split("\n")
    .map((i) => i.split(" "));

  // 一行目は破棄する
  input.shift();

  input.map((i) => {
    const command = i[0];
    console.log(i);
    switch (command) {
      case "0": {
        // 着席
        const table = Number(i[1]);
        const favorite = i.splice(3);
        regist(table, favorite);
        break;
      }
      case "1": {
        // ネタを流す
        const neta = i[1];
        eat(neta);
        break;
      }
      case "2": {
        // 退席
        const table = Number(i[1]);
        remove(table);
        break;
      }
      default: {
        break;
      }
    }
  });
};

const regist = (table: number, favorite: string[]) => {
  Users.push({ table, favorite });
  Users = Users.sort((u) => u.table);
};

const remove = (table: number) => {
  Users = Users.filter((u) => u.table !== table);
};

const eat = (favorite: string) => {
  for (const u of Users) {
    const idx = u.favorite.findIndex((u) => u === favorite);
    if (idx > -1) {
      u.favorite.splice(idx, 1);
      console.log(u.table);
      return;
    }
  }
  console.log(-1);
};

interface User {
  table: number;
  favorite: string[];
}

// debug
// main(
//   [
//     "11",
//     "1 toro",
//     "1 unagi",
//     "0 14 4 maguroakami hotatekai unagi maguroakami",
//     "1 saamonnmottu",
//     "1 unagi",
//     "1 unagi",
//     "1 maguro",
//     "1 kouika",
//     "1 maguroakami",
//     "1 maguroakami",
//     "2 14",
//   ].join("\n")
// );
// release
main(readFileSync("/dev/stdin", "utf8"));
0