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(); 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(); 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 netaList { get; } public Customer(int num, List neta) { tableNumber = num; netaList = neta; } } }