結果

問題 No.138 化石のバージョン
ユーザー yo-kondo
提出日時 2019-05-18 18:45:46
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 1,345 bytes
コンパイル時間 13,416 ms
コンパイル使用メモリ 385,304 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-17 06:15:06
合計ジャッジ時間 13,280 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::stdin;

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

/// 標準入力から文字列を取得します。
fn read_lines() -> (String, String) {
    let mut str1 = String::new();
    stdin().read_line(&mut str1).unwrap();
    str1 = str1.trim().to_string();

    let mut str2 = String::new();
    stdin().read_line(&mut str2).unwrap();
    str2 = str2.trim().to_string();
    (str1, str2)
}

///対象のバージョンか化石のバージョンかどうかを返します。
/// ## arguments
/// * `fossil` - 化石のバージョン
/// * `target_version` - 対象のバージョン
fn version_check(fossil: String, target_version: String) -> String {
    let old_version = fossil
        .split(".")
        .collect::<Vec<&str>>()
        .iter()
        .map(|&x| x.parse().unwrap())
        .collect::<Vec<i32>>();

    let new_version = target_version
        .split(".")
        .collect::<Vec<&str>>()
        .iter()
        .map(|&x| x.parse().unwrap())
        .collect::<Vec<i32>>();

    for i in 0..(old_version.len()) {
        if old_version[i] < new_version[i] {
            return "NO".to_string();
        }
        if old_version[i] > new_version[i] {
            return "YES".to_string();
        }
    }
    "YES".to_string()
}
0