結果

問題 No.708 (+ー)の式
ユーザー TheRustWizardOfTheCenturyTheRustWizardOfTheCentury
提出日時 2018-06-29 23:30:23
言語 Rust
(1.72.1)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 1,453 ms
コンパイル使用メモリ 130,196 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 15:42:42
合計ジャッジ時間 1,561 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).unwrap();
    let mut tok = buf.split_whitespace();
    let mut get = || tok.next().unwrap();
    
    let expr = get().as_bytes();
    
    let mut ans = 0;
    let mut sign = 1;
    let mut bra = 1;
    
    for &ch in expr {
        match ch {
        b'+' => sign = 1,
        b'-' => sign = -1,
        b'(' => {
            bra = sign;
            sign = 1;
        },
        b')' => {
            bra = 1;
            sign = 1;
        },
        ch => {
            let v = ch as i64 - b'0' as i64;
            ans += sign * bra * v;
        },
        };
    }
    println!("{}", ans);
}
0