結果

問題 No.714 回転寿司屋のシミュレート
ユーザー Charlotte8687Charlotte8687
提出日時 2018-11-28 15:38:54
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 2,801 bytes
コンパイル時間 2,000 ms
コンパイル使用メモリ 61,696 KB
実行使用メモリ 25,104 KB
最終ジャッジ日時 2023-09-09 05:47:08
合計ジャッジ時間 5,692 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
22,896 KB
testcase_01 AC 68 ms
22,892 KB
testcase_02 AC 68 ms
22,900 KB
testcase_03 AC 69 ms
22,916 KB
testcase_04 AC 70 ms
22,796 KB
testcase_05 AC 71 ms
22,860 KB
testcase_06 AC 74 ms
24,960 KB
testcase_07 AC 79 ms
22,984 KB
testcase_08 AC 87 ms
24,920 KB
testcase_09 AC 74 ms
22,916 KB
testcase_10 AC 73 ms
22,972 KB
testcase_11 AC 72 ms
20,980 KB
testcase_12 AC 74 ms
23,008 KB
testcase_13 AC 74 ms
25,072 KB
testcase_14 AC 73 ms
24,956 KB
testcase_15 AC 73 ms
22,852 KB
testcase_16 AC 73 ms
21,012 KB
testcase_17 AC 74 ms
24,904 KB
testcase_18 AC 73 ms
23,020 KB
testcase_19 AC 73 ms
25,104 KB
testcase_20 AC 72 ms
22,996 KB
testcase_21 AC 72 ms
22,908 KB
testcase_22 AC 70 ms
23,000 KB
testcase_23 AC 69 ms
24,964 KB
testcase_24 AC 70 ms
22,888 KB
testcase_25 AC 70 ms
23,012 KB
testcase_26 AC 70 ms
24,980 KB
testcase_27 AC 70 ms
22,928 KB
testcase_28 AC 70 ms
24,972 KB
testcase_29 AC 70 ms
23,060 KB
testcase_30 AC 66 ms
24,820 KB
testcase_31 AC 66 ms
22,832 KB
testcase_32 AC 67 ms
22,872 KB
testcase_33 AC 66 ms
20,896 KB
testcase_34 AC 66 ms
24,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

namespace StudyProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            var restaurant = new Restaurant();
            string line;
            List<string> inputs = new List<string>();

            while (!string.IsNullOrEmpty(line = Console.ReadLine()))
            {
                inputs.Add(line);
            }
            CheckData(inputs, restaurant);
        }

        static void CheckData(List<string> inputs, Restaurant restaurant)
        {
            Person person = null;

            foreach (var line in inputs)
            {
                string[] input = line.Split(' ');
                string dataNo = input[0];

                switch (dataNo)
                {
                    case "0":
                        person = new Person(int.Parse(input[1]), GetFoods(input));
                        restaurant.AddPerson(person);
                        break;
                    case "1":
                        restaurant.ProvideFood(input[1]);
                        break;
                    case "2":
                        restaurant.LeavePerson(int.Parse(input[1]));
                        break;
                    default:
                        break;
                }
            }
        }

        static IEnumerable<string> GetFoods(string[] order)
        {
            foreach (var food in order)
            {
                if (!int.TryParse(food, out int num))
                    yield return food;
            }
        }
    }

    class Person
    {
        public int Seat { get; private set; }
        public List<string> Foods { get; private set; }

        public Person(int seat, IEnumerable<string> foods)
        {
            this.Seat = seat;
            this.Foods = foods.ToList();
        }

        public bool EatFood(string food)
        {
            if (this.Foods.Contains(food))
            {
                Foods.Remove(food);
                return true;
            }
            else
            {
                return false;
            }
        }
    }

    class Restaurant
    {
        SortedList<int, Person> persons = new SortedList<int, Person>();

        public int GetPersonNum() => persons.Count;

        public void AddPerson(Person person) => persons?.Add(person.Seat, person);

        public void LeavePerson(int seat) => persons?.Remove(seat);

        public void ProvideFood(string food)
        {
            foreach (var person in persons)
            {
                if (person.Value.EatFood(food))
                {
                    Console.WriteLine(person.Key);
                    return;
                }
            }
            Console.WriteLine("-1");
        }
    }
}
0