結果

問題 No.714 回転寿司屋のシミュレート
ユーザー TomoProgTomoProg
提出日時 2018-10-11 00:08:47
言語 Ruby
(3.3.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,162 bytes
コンパイル時間 35 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-04-20 19:33:27
合計ジャッジ時間 4,078 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
12,160 KB
testcase_01 AC 80 ms
12,288 KB
testcase_02 AC 78 ms
12,032 KB
testcase_03 AC 79 ms
12,160 KB
testcase_04 AC 81 ms
12,160 KB
testcase_05 AC 86 ms
12,288 KB
testcase_06 AC 88 ms
12,288 KB
testcase_07 AC 105 ms
12,416 KB
testcase_08 AC 110 ms
12,416 KB
testcase_09 AC 89 ms
12,288 KB
testcase_10 AC 91 ms
12,288 KB
testcase_11 AC 87 ms
12,288 KB
testcase_12 AC 91 ms
12,288 KB
testcase_13 AC 90 ms
12,288 KB
testcase_14 AC 87 ms
12,416 KB
testcase_15 AC 86 ms
12,416 KB
testcase_16 AC 88 ms
12,288 KB
testcase_17 AC 88 ms
12,416 KB
testcase_18 AC 92 ms
12,416 KB
testcase_19 AC 89 ms
12,544 KB
testcase_20 AC 86 ms
12,416 KB
testcase_21 AC 86 ms
12,160 KB
testcase_22 AC 83 ms
12,160 KB
testcase_23 AC 83 ms
12,416 KB
testcase_24 AC 83 ms
12,288 KB
testcase_25 AC 83 ms
12,416 KB
testcase_26 AC 85 ms
12,160 KB
testcase_27 AC 86 ms
12,160 KB
testcase_28 AC 86 ms
12,544 KB
testcase_29 AC 86 ms
12,288 KB
testcase_30 AC 81 ms
12,288 KB
testcase_31 AC 75 ms
12,160 KB
testcase_32 AC 80 ms
12,288 KB
testcase_33 AC 78 ms
12,032 KB
testcase_34 AC 76 ms
12,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Order
  attr_reader :name
  def initialize(name)
    @name = name
  end

  def ==(other)
    self.name == other.name
  end
end

class Customer
  def initialize(orders)
    @orders = orders
  end

  def has_order?(order)
    @orders.include?(order)
  end

  def delete_order(order)
    @orders.delete_at(@orders.find_index(order))
  end
end

def create_customer(sushi_neta_names)
  Customer.new(
    sushi_neta_names.map do |neta|
      Order.new(neta)
    end
  )
end

SEAT_MAX_NUM = 20
seat_list = Array.new(SEAT_MAX_NUM)

data_num = gets.to_i
data_num.times do
  data = gets.split
  if data[0] == '0'
    # 席に座る
    seat_number = data[1].to_i
    seat_list[seat_number] = create_customer(data[3..-1])
  elsif data[0] == '1'
    # 寿司を投入
    ate_customer_number = -1
    order = Order.new(data[1])
    seat_list.each_with_index do |customer, i|
      next if customer.nil?
      if customer.has_order?(order)
        customer.delete_order(order)
        ate_customer_number = i
        break
      end
    end
    puts ate_customer_number
  else
    # 退席する
    seat_number = data[1].to_i
    seat_list[seat_number] = nil
  end
end
0