結果
| 問題 |
No.714 回転寿司屋のシミュレート
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-11-28 15:38:54 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 2,000 ms |
| コード長 | 2,801 bytes |
| コンパイル時間 | 3,901 ms |
| コンパイル使用メモリ | 114,500 KB |
| 実行使用メモリ | 28,868 KB |
| 最終ジャッジ日時 | 2024-06-26 22:56:22 |
| 合計ジャッジ時間 | 6,517 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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");
}
}
}