結果

問題 No.48 ロボットの操縦
ユーザー yo-kondoyo-kondo
提出日時 2019-03-03 16:22:52
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,357 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 141,468 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 17:46:36
合計ジャッジ時間 1,648 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::stdin;

/// エントリポイント
fn main() {
    let in1 = read_line();
    let in2 = read_line();
    let in3 = read_line();
    println!("{}", count_order(in1, in2, in3));
}

/// 移動先に到達するまでに必要な最小の命令回数を計算します。
///
/// ## arguments
/// * `east_west` - 目的地の東西方向
/// * `north_south` - 目的地の南北方向
/// * `max_distance` - ロボットが1命令につき前進することができる最大の距離
fn count_order(east_west: String, north_south: String, max_distance: String) -> i32 {
    let mut num = 0;
    let ew: f64 = east_west.trim().parse().unwrap();
    let ns: f64 = north_south.trim().parse().unwrap();
    let md: f64 = max_distance.trim().parse().unwrap();

    // 北
    if ns > 0.0 {
        num += (ns / md).abs().ceil() as i32;
    }

    // 東西
    if ew != 0.0 {
        num += 1;
        num += (ew / md).abs().ceil() as i32;
    }

    // 北から南へ向く場合、いったん東西へ向く
    if ew == 0.0 && ns < 0.0 {
        num += 1;
    }

    // 南
    if ns < 0.0 {
        num += 1;
        num += (ns / md).abs().ceil() as i32;
    }

    num
}

/// 標準入力から1行取得して返します。
fn read_line() -> String {
    let mut input = String::new();
    stdin().read_line(&mut input).unwrap();
    input
}
0