結果

問題 No.35 タイパー高橋
ユーザー yo-kondoyo-kondo
提出日時 2019-03-02 16:34:43
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,722 bytes
コンパイル時間 1,385 ms
コンパイル使用メモリ 145,912 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 16:55:45
合計ジャッジ時間 1,928 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::io::stdin;

/// 入力データ
struct InputData {
    /// ゲーム数
    _count: i32,
    /// 問題
    questions: Vec<Question>,
}

/// 問題
struct Question {
    /// 制限時間
    limit: i32,
    /// 入力すべき文字列
    type_str: String,
}

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

/// タイピングゲームの結果を返します。
/// # 戻り値
/// 以下の値を格納したタプル
/// 0: 正しくタイプできる文字数
/// 1: タイプできずに逃してしまう文字数
fn typing(input: InputData) -> (i32, i32) {
    let mut ok_type = 0;
    let mut ng_type = 0;

    for qu in input.questions {
        let type_num = 12 * qu.limit / 1000;

        let str_len = qu.type_str.len() as i32;

        if type_num >= str_len {
            ok_type += str_len;
        } else {
            ok_type += type_num;
            ng_type += str_len - type_num;
        }
    }
    (ok_type, ng_type)
}

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

    // 2行目以降
    let mut questions = Vec::new();
    for _i in 0..count {
        let mut q = String::new();
        stdin().read_line(&mut q).unwrap();

        let sp: Vec<&str> = q.trim().split_whitespace().collect();
        questions.push(Question {
            limit: sp[0].trim().parse().unwrap(),
            type_str: sp[1].to_string(),
        });
    }
    InputData {
        _count: count,
        questions,
    }
}
0