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