結果

問題 No.714 回転寿司屋のシミュレート
ユーザー Yosuke Kono
提出日時 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

ソースコード

diff #
プレゼンテーションモードにする

class Customer
attr_accessor :position #
attr_accessor :want_toppings #
def initialize(position, toppings)
@position, @want_toppings = position, toppings
end
def eat(topping_name)
index = @want_toppings.index(topping_name)
unless index.nil?
@want_toppings.delete_at(index)
return true
end
false
end
end
class SushiDish
attr_accessor :position #
attr_accessor :topping_name #
def initialize(topping_name, position = 1)
@topping_name, @position = topping_name, position
end
# nil
def move
if @position < ConveyorBeltSushiSystem::SEAT_LENGTH
@position += 1
else
@position = nil
end
end
end
class ConveyorBeltSushiSystem
SEAT_LENGTH = 20
attr_accessor :dishes
attr_accessor :customers
def initialize
@dishes = Array.new(self.class::SEAT_LENGTH, nil)
@customers = Array.new(self.class::SEAT_LENGTH, nil)
end
def go_round
@customers.each do |customer|
@dishes.each do |dish|
customer.eat(dish)
end
end
@dishes.each do |dish|
dish.move
end
end
end
DATA_CUSTOMER = 0 # [1][2][3]n1...[4+n]n
DATA_SUSHI = 1 # 寿寿
DATA_CHECK = 2 #
system = ConveyorBeltSushiSystem.new
data_length = gets.to_i
data_lines = []
data_length.times do
data_lines.push(gets.split)
end
data_lines.each do |data|
data[0] = data[0].to_i
if data[0] == DATA_CUSTOMER
want_topping_data_starts_at = 3 # 0
position = data[1].to_i #
want_toppings_size = data[2].to_i
want_toppings = [] #
(want_topping_data_starts_at..data.size).each do |index|
want_toppings.push(data[index])
end
customer = Customer.new(position, want_toppings)
system.customers[customer.position - 1] = customer
elsif data[0] == DATA_SUSHI
topping_name = data[1] # 寿
is_eaten = false
system.customers.compact.each do |customer|
is_eaten = customer.eat(topping_name) #
if is_eaten
puts customer.position
break
end
end
puts -1 unless is_eaten
elsif data[0] == DATA_CHECK
system.customers[data[1].to_i - 1] = nil
else
raise 'invalid data type.'
end
end
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0