結果

問題 No.480 合計
ユーザー cm-kojimat
提出日時 2020-07-02 15:22:12
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 773 bytes
コンパイル時間 13,235 ms
コンパイル使用メモリ 385,652 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-15 01:00:48
合計ジャッジ時間 14,005 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct Input {
    n: i32,
}

fn read_input(cin_lock: &mut StdinLock) -> Input {
    let n = next_token(cin_lock);
    Input { n }
}

fn solve(input: Input) {
    let mut sum = 0;
    for i in 1..input.n + 1 {
        sum += i
    }
    println!("{}", sum)
}

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