結果

問題 No.9008 空白区切りで与えられる数値データの合計値を求める(テスト用)
ユーザー mai
提出日時 2021-04-21 01:41:59
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,001 bytes
コンパイル時間 14,939 ms
コンパイル使用メモリ 400,264 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-04 05:49:03
合計ジャッジ時間 14,093 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `collections::*`
 --> src/main.rs:1:30
  |
1 | use std::{borrow::BorrowMut, collections::*, io::Read};
  |                              ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

ソースコード

diff #

use std::{borrow::BorrowMut, collections::*, io::Read};

struct Scanner<R: std::io::BufRead>(R);

impl<R: std::io::BufRead> Scanner<R> {
    fn new(input: R) -> Self {
        Self(input)
    }
    fn take(&mut self) -> String {
        self.0
            .borrow_mut()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
    }
}

#[allow(unused)]
macro_rules! scan {
    ($io:expr => $t:ty) => ($io.take().parse::<$t>().unwrap());
    ($io:expr => $t:tt * $n:expr) => ((0..$n).map(|_| scan!($io => $t)).collect::<Vec<_>>());
    ($io:expr => $($t:tt),*) => (($(scan!($io => $t)),*));
}

fn main() {
    solve(Scanner::<std::io::StdinLock>::new(std::io::stdin().lock()))
}

fn solve<R: std::io::BufRead>(mut cin: Scanner<R>) {
    let n = scan!(cin => i32);
    let aa = scan!(cin => i64 * n);
    let total = aa.iter().sum::<i64>();
    println!("{}", total);
}
0