結果

問題 No.70 睡眠の重要性!
ユーザー yo-kondoyo-kondo
提出日時 2019-03-31 09:44:35
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,562 bytes
コンパイル時間 10,847 ms
コンパイル使用メモリ 399,580 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-05-01 04:25:53
合計ジャッジ時間 11,607 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,812 KB
testcase_01 AC 0 ms
6,816 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::stdin;

/// エントリポイント
fn main() {
    let input = read_lines();
    println!("{}", sleep(input));
}

/// 標準入力から文字列を取得します。
fn read_lines() -> Vec<String> {
    // 1行目
    let mut str1 = String::new();
    stdin().read_line(&mut str1).unwrap();
    let num_count: i32 = str1.trim().parse().unwrap();

    // 2行目以降
    let mut sleep_time = Vec::new();
    // 1行目で取得したデータ件数分ループ
    for _i in 0..num_count {
        let mut str2 = String::new();
        stdin().read_line(&mut str2).unwrap();
        sleep_time.push(str2.trim().to_string());
    }
    sleep_time
}

/// 睡眠時間の合計を分で返します。
fn sleep(input: Vec<String>) -> i32 {
    // 定数 1日の分
    const DAY_MINUTES: i32 = 24 * 60;

    let mut sleep_time = 0;

    for line in input {
        let sp: Vec<&str> = line.split_whitespace().collect();

        let start_time = get_minutes(sp[0]);
        let end_time = get_minutes(sp[1]);

        if start_time < end_time {
            // マイナス値になるので絶対値に変換
            sleep_time += (start_time - end_time).abs();
        } else {
            sleep_time += end_time + DAY_MINUTES - start_time;
        }
    }
    sleep_time
}

/// HH:mm 形式の文字列を分に変換して返します。
fn get_minutes(str_time: &str) -> i32 {
    let sp: Vec<&str> = str_time.split(":").collect();
    let hour: i32 = sp[0].parse().unwrap();
    let min: i32 = sp[1].parse().unwrap();
    hour * 60 + min
}
0