結果

問題 No.48 ロボットの操縦
コンテスト
ユーザー rky
提出日時 2017-11-06 11:24:38
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
WA  
実行時間 -
コード長 639 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 210 ms
コンパイル使用メモリ 9,088 KB
実行使用メモリ 29,440 KB
最終ジャッジ日時 2026-05-17 23:56:05
合計ジャッジ時間 7,266 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 WA * 1 TLE * 1 -- * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

class No48
	attr_accessor :width, :height, :distance, :count

	def initialize
		@width, @height, @distance = gets.chomp.to_i, gets.chomp.to_i, gets.chomp.to_i
		@count = 0
	end

	def negative_number(num)
		if num < 0
			num *= -1
			@count += 1
		end
		num
	end

	def move_on(num)
		unless num == 0
			num < @distance ? num = 0 : num -= @distance
			@count += 1
		end
		num
	end

	def run
		@width = self.negative_number(@width)
		@height = self.negative_number(@height)
		loop{
			@width = self.move_on(@width)
			@height = self.move_on(@height)
			break if @width == 0 && @height == 0
		}
		@count
	end
end

no48 = No48.new
puts no48.run
0