結果

問題 No.714 回転寿司屋のシミュレート
ユーザー Rim_EarthLightsRim_EarthLights
提出日時 2019-02-06 16:42:47
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 4,889 bytes
コンパイル時間 3,815 ms
コンパイル使用メモリ 111,388 KB
実行使用メモリ 25,924 KB
最終ジャッジ日時 2023-09-02 15:25:07
合計ジャッジ時間 8,143 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
21,716 KB
testcase_01 AC 73 ms
21,612 KB
testcase_02 AC 74 ms
21,680 KB
testcase_03 AC 74 ms
21,680 KB
testcase_04 AC 76 ms
21,704 KB
testcase_05 AC 80 ms
21,756 KB
testcase_06 AC 81 ms
21,688 KB
testcase_07 AC 93 ms
23,656 KB
testcase_08 AC 99 ms
25,924 KB
testcase_09 AC 83 ms
23,848 KB
testcase_10 AC 81 ms
21,856 KB
testcase_11 AC 83 ms
21,832 KB
testcase_12 AC 82 ms
21,632 KB
testcase_13 AC 84 ms
23,764 KB
testcase_14 AC 80 ms
21,756 KB
testcase_15 AC 79 ms
21,676 KB
testcase_16 AC 79 ms
19,580 KB
testcase_17 AC 81 ms
23,900 KB
testcase_18 AC 83 ms
23,836 KB
testcase_19 AC 80 ms
19,680 KB
testcase_20 AC 82 ms
21,684 KB
testcase_21 AC 79 ms
21,832 KB
testcase_22 AC 79 ms
21,820 KB
testcase_23 AC 79 ms
23,800 KB
testcase_24 AC 77 ms
23,776 KB
testcase_25 AC 77 ms
23,840 KB
testcase_26 AC 78 ms
21,816 KB
testcase_27 AC 78 ms
23,820 KB
testcase_28 AC 79 ms
21,716 KB
testcase_29 AC 79 ms
23,908 KB
testcase_30 AC 73 ms
23,644 KB
testcase_31 AC 74 ms
23,748 KB
testcase_32 AC 75 ms
23,768 KB
testcase_33 AC 73 ms
23,724 KB
testcase_34 AC 72 ms
21,900 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) {
            // Console.Write("order length: ");
            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++) {
                // Console.Write("order: ");
                var order = Console.ReadLine().Trim().Split(' ');
                int type = int.Parse(order[0]);
                switch (type) {
                    case 0: // 入店処理
                        var tableNum = int.Parse(order[1]);
                        var netas = new List<string>();

                        if(customers.Where(x => x.tableNumber == tableNum).Count() == 0) {
                            if(tableNum < 21) { // テーブル番号20以下
                                //Console.WriteLine("-> table ({0})", tableNum);
                               // Console.Write("-> neta > ");
                                for (int j = 3; j < order.Length; j++) {
                                    netas.Add(order[j]);
                                   // Console.Write("{0} ", order[j]);
                                }
                                customers.Add(new Customer(tableNum, netas));
                                //Console.WriteLine();
                            }
                            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 < 0) {
                                // 見つからなかった
                            }
                            else {
                                Console.WriteLine(c.tableNumber);
                                //Console.WriteLine("-> ({0}) table [{0}] eat {1}.", c.tableNumber, order[1]);
                                c.netaList.Remove(order[1]);
                                eatFlg = true;
                                break;
                            }
                        }
                        if(!eatFlg) {
                            // 最後まで食べられなかった
                            Console.WriteLine("-1");
                            //Console.WriteLine("-> (-1) No one eat {0}.");
                        }
                        break;
                    case 2: // 退店処理
                        var cs = customers.Where(c => c.tableNumber == int.Parse(order[1]));
                        if (cs.Count() > 0) {
                            //Console.WriteLine("-> table ({0}) leave.", cs.First().tableNumber);
                            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