結果
| 問題 |
No.714 回転寿司屋のシミュレート
|
| コンテスト | |
| ユーザー |
Rim_EarthLights
|
| 提出日時 | 2019-02-06 17:19:51 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 2,000 ms |
| コード長 | 4,562 bytes |
| コンパイル時間 | 2,544 ms |
| コンパイル使用メモリ | 110,592 KB |
| 実行使用メモリ | 23,552 KB |
| 最終ジャッジ日時 | 2024-06-12 02:49:12 |
| 合計ジャッジ時間 | 5,145 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
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;
}
}
}
Rim_EarthLights