結果
問題 | No.714 回転寿司屋のシミュレート |
ユーザー |
|
提出日時 | 2018-10-17 22:52:00 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 108 ms / 2,000 ms |
コード長 | 2,732 bytes |
コンパイル時間 | 94 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 14,208 KB |
最終ジャッジ日時 | 2024-10-12 18:57:00 |
合計ジャッジ時間 | 4,241 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
コンパイルメッセージ
Main.rb:97: warning: ambiguous first argument; put parentheses or a space even after `-' operator Main.rb:79: warning: assigned but unused variable - want_toppings_size Syntax OK
ソースコード
class Customerattr_accessor :position # 席番号attr_accessor :want_toppings # 欲しいネタリストdef initialize(position, toppings)@position, @want_toppings = position, toppingsenddef eat(topping_name)index = @want_toppings.index(topping_name)unless index.nil?@want_toppings.delete_at(index)return trueendfalseendendclass SushiDishattr_accessor :position # 席番号attr_accessor :topping_name # ネタ名def initialize(topping_name, position = 1)@topping_name, @position = topping_name, positionend# 皿の移動。移動後の席の位置を返す。最後の席の位置にいたら nil を返すdef moveif @position < ConveyorBeltSushiSystem::SEAT_LENGTH@position += 1else@position = nilendendendclass ConveyorBeltSushiSystemSEAT_LENGTH = 20attr_accessor :dishesattr_accessor :customersdef initialize@dishes = Array.new(self.class::SEAT_LENGTH, nil)@customers = Array.new(self.class::SEAT_LENGTH, nil)enddef go_round@customers.each do |customer|@dishes.each do |dish|customer.eat(dish)endend@dishes.each do |dish|dish.moveendendendDATA_CUSTOMER = 0 # 客がくる。「[1]席番号、[2]食べたいものリストの要素数、[3]n食べたいもの1、...、[4+n]食べたいものn」DATA_SUSHI = 1 # 寿司がコンベアに流される。「寿司ネタの名前」DATA_CHECK = 2 # 客が会計する。「会計する客の席番号」system = ConveyorBeltSushiSystem.newdata_length = gets.to_idata_lines = []data_length.times dodata_lines.push(gets.split)enddata_lines.each do |data|data[0] = data[0].to_iif data[0] == DATA_CUSTOMERwant_topping_data_starts_at = 3 # データタイプ 0 の食べたいものリストが始まる要素番号position = data[1].to_i # 客が座る座席番号want_toppings_size = data[2].to_iwant_toppings = [] # 食べたいものリスト(want_topping_data_starts_at..data.size).each do |index|want_toppings.push(data[index])endcustomer = Customer.new(position, want_toppings)system.customers[customer.position - 1] = customerelsif data[0] == DATA_SUSHItopping_name = data[1] # 寿司ネタの名前is_eaten = falsesystem.customers.compact.each do |customer|is_eaten = customer.eat(topping_name) # 客が食べたら次のデータの処理へif is_eatenputs customer.positionbreakendendputs -1 unless is_eatenelsif data[0] == DATA_CHECKsystem.customers[data[1].to_i - 1] = nilelseraise 'invalid data type.'endend