結果

問題 No.9008 空白区切りで与えられる数値データの合計値を求める(テスト用)
ユーザー cm-kojimatcm-kojimat
提出日時 2020-07-02 15:53:18
言語 Rust
(1.77.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 804 bytes
コンパイル時間 3,827 ms
コンパイル使用メモリ 141,316 KB
実行使用メモリ 5,824 KB
最終ジャッジ日時 2023-10-13 03:23:46
合計ジャッジ時間 2,080 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 5 ms
4,348 KB
testcase_08 AC 19 ms
4,348 KB
testcase_09 AC 15 ms
4,348 KB
testcase_10 AC 32 ms
5,048 KB
testcase_11 AC 34 ms
5,044 KB
testcase_12 AC 34 ms
5,096 KB
testcase_13 AC 35 ms
5,316 KB
testcase_14 AC 35 ms
5,264 KB
testcase_15 AC 36 ms
5,308 KB
testcase_16 AC 40 ms
5,824 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Input {
    a: Vec<usize>,
}

fn read_input(cin_lock: &mut StdinLock) -> Input {
    let n = next_token(cin_lock);
    Input {
        a: (0..n).map(|_| next_token(cin_lock)).collect(),
    }
}

fn solve(input: Input) {
    println!("{}", input.a.iter().fold(0, |acc, v| acc + v))
}

fn next_token<T: FromStr>(cin_lock: &mut StdinLock) -> T {
    cin_lock
        .by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>()
        .parse::<T>()
        .ok()
        .unwrap()
}

fn main() {
    let cin = stdin();
    let mut cin_lock = cin.lock();
    let input = read_input(&mut cin_lock);
    solve(input);
}
0