結果

問題 No.9008 空白区切りで与えられる数値データの合計値を求める(テスト用)
ユーザー halshiphalship
提出日時 2017-08-02 17:18:37
言語 Rust
(1.77.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 842 bytes
コンパイル時間 6,096 ms
コンパイル使用メモリ 131,840 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 13:32:21
合計ジャッジ時間 1,768 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

use std::io::{self, Read};

fn read_usize<R: Read>(reader: &mut R) -> usize {
    reader
        .by_ref()
        .bytes()
        .filter_map(|b| b.ok())
        .skip_while(|&b| b < b'0' || b > b'9')
        .take_while(|&b| b >= b'0' && b <= b'9')
        .map(|b| (b - b'0') as usize)
        .fold(0, |res, n| res * 10 + n)
}

fn read_u64<R: Read>(reader: &mut R) -> u64 {
    reader
        .by_ref()
        .bytes()
        .filter_map(|b| b.ok())
        .skip_while(|&b| b < b'0' || b > b'9')
        .take_while(|&b| b >= b'0' && b <= b'9')
        .map(|b| (b - b'0') as u64)
        .fold(0, |res, n| res * 10 + n)
}

fn main() {
    let stdin = io::stdin();
    let mut stdin = stdin.lock();

    let n: usize = read_usize(&mut stdin);
    let sum: u64 = (0..n).map(|_| read_u64(&mut stdin)).sum();

    println!("{}", sum);
}
0