結果

問題 No.714 回転寿司屋のシミュレート
ユーザー Rim_EarthLightsRim_EarthLights
提出日時 2019-02-06 17:19:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 4,562 bytes
コンパイル時間 5,109 ms
コンパイル使用メモリ 110,212 KB
実行使用メモリ 27,984 KB
最終ジャッジ日時 2023-09-02 20:27:56
合計ジャッジ時間 9,587 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
19,664 KB
testcase_01 AC 69 ms
21,760 KB
testcase_02 AC 73 ms
21,808 KB
testcase_03 AC 74 ms
21,780 KB
testcase_04 AC 75 ms
21,788 KB
testcase_05 AC 78 ms
21,652 KB
testcase_06 AC 80 ms
21,756 KB
testcase_07 AC 91 ms
21,772 KB
testcase_08 AC 99 ms
27,984 KB
testcase_09 AC 85 ms
21,728 KB
testcase_10 AC 81 ms
21,728 KB
testcase_11 AC 85 ms
21,788 KB
testcase_12 AC 81 ms
23,836 KB
testcase_13 AC 82 ms
23,800 KB
testcase_14 AC 79 ms
21,748 KB
testcase_15 AC 80 ms
23,768 KB
testcase_16 AC 79 ms
21,808 KB
testcase_17 AC 80 ms
23,716 KB
testcase_18 AC 81 ms
21,756 KB
testcase_19 AC 79 ms
21,752 KB
testcase_20 AC 79 ms
21,772 KB
testcase_21 AC 80 ms
21,768 KB
testcase_22 AC 77 ms
21,780 KB
testcase_23 AC 77 ms
23,824 KB
testcase_24 AC 79 ms
21,756 KB
testcase_25 AC 76 ms
21,664 KB
testcase_26 AC 77 ms
21,704 KB
testcase_27 AC 78 ms
23,664 KB
testcase_28 AC 77 ms
23,708 KB
testcase_29 AC 78 ms
19,672 KB
testcase_30 AC 71 ms
21,648 KB
testcase_31 AC 73 ms
21,708 KB
testcase_32 AC 73 ms
21,744 KB
testcase_33 AC 72 ms
21,732 KB
testcase_34 AC 73 ms
21,764 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// No.714 回転寿司屋のシミュレート
// https://yukicoder.me/problems/no/714

namespace no714 {
    class MainProgram {
        static void Main(string[] args) {

            // 発行される命令数
            int len = -1;
            for (int i = 0; i < 10;) {
                if (int.TryParse(Console.ReadLine().Trim(), out len)) {
                    break;
                }
                else {
                    Console.WriteLine("-> E: not a number.");
                }
            }

            var customers = new List<Customer>();

            for (int i = 0; i < len; i++) {
                var order = Console.ReadLine().Trim().Split(' ');
                int type = int.Parse(order[0]);
                switch (type) {
                    case 0: // 入店処理 0 [席番号] [ネタ数] [ネタ] x(ネタ数)個
                        var tableNum = int.Parse(order[1]);
                        var netas = new List<string>();

                        // 該当テーブルが使われてないかつ20以下
                        if(customers.Where(x => x.tableNumber == tableNum).Count() == 0) {
                            if(tableNum < 21 && tableNum > 0) { 
                                for (int j = 3; j < order.Length; j++) {
                                    netas.Add(order[j]);
                                }
                                customers.Add(new Customer(tableNum, netas));
                            }
                            else {
                                Console.WriteLine("E: table number have to 1 - 20.");
                            }
                        }
                        else {
                            Console.WriteLine("E: Already use table ({0}).", tableNum);
                        }
                        break;
                    case 1: // ネタ流し
                        // テーブル番号が若い順で食べる(優先される)ためソート
                        customers = customers.OrderBy(x => x.tableNumber).ToList();
                        int c_index = -1;
                        bool eatFlg = false;
                        foreach (var c in customers) {
                            c_index = c.netaList.IndexOf(order[1]);
                            if(c_index > -1) {
                                Console.WriteLine(c.tableNumber);
                                c.netaList.Remove(order[1]);
                                eatFlg = true;
                                break;
                            }
                        }
                        if(!eatFlg) {
                            // 最後まで誰にも食べられなかった
                            Console.WriteLine("-1");
                        }
                        break;
                    case 2: // 退店処理
                        var cs = customers.Where(c => c.tableNumber == int.Parse(order[1]));
                        // 席に座っていれば退店する
                        if (cs.Count() > 0) {
                            customers.Remove(cs.First());
                        }
                        else {
                            Console.WriteLine("E: table number ({0}) Empty.", order[1]);
                        }
                        break;
                    case 9: // デバッグ用 今いる客表示
                        Console.WriteLine("-----------------------");
                        foreach (var c in customers) {
                            Console.WriteLine("table: {0}", c.tableNumber);
                            Console.Write("neta : ");
                            foreach(var neta in c.netaList) {
                                Console.Write("{0} ", neta);
                            }
                            Console.WriteLine("\n-----------------------");
                        }
                        break;
                    default:
                        break;
                }
            }
            // Console.WriteLine("exit for press any key");
            // Console.ReadKey();
        }
    }

    // 客クラス テーブル番号とほしいネタリスト保存
    public class Customer {
        public int tableNumber { get; }
        public List<string> netaList { get; }

        public Customer(int num, List<string> neta) {
            tableNumber = num;
            netaList = neta;
        }
    }
}
0