結果

問題 No.48 ロボットの操縦
ユーザー korogy
提出日時 2017-09-08 00:07:40
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 976 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-11-07 11:52:31
合計ジャッジ時間 3,484 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 24 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class PilotRobot
    attr_reader :x, :y, :l

    def initialize(x: 0, y: 0, l: 0)
        @x, @y, @l = x, y, l
    end

    def datainput
        begin
            @x = Integer(gets.chomp)
            @y = Integer(gets.chomp)
            @l = Integer(gets.chomp)
        rescue
            
        end
    end

    def pilot(x, y, l)
        action = 0
        
        # y方向の移動
        action += y.abs / l
        action += 1 if 0 < (y.abs % l)
        
        # x方向の移動
        action += x.abs / l
        action += 1 if 0 < (x.abs % l)
        
        # x方向の回転
        action += 1 if x != 0
        
        # y方向の回転
        if y < 0
          action += 1
          #action += 1 if x == 0
        end
        
        return (x == 0 and y == 0)? 0 : action
    end

    def dataoutput
        puts pilot(@x, @y, @l)
    end

    def run
        datainput
        dataoutput
    end
end

if $0 == __FILE__
    PilotRobot.new.run
end
0