結果

問題 No.222 引き算と足し算
ユーザー tonyu0tonyu0
提出日時 2020-04-26 18:50:55
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 1,596 bytes
コンパイル時間 12,889 ms
コンパイル使用メモリ 378,300 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 21:38:38
合計ジャッジ時間 15,081 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 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 WA -
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 WA -
testcase_21 AC 0 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 1 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 1 ms
5,376 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 0 ms
5,376 KB
testcase_31 WA -
testcase_32 AC 1 ms
5,376 KB
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let s: Vec<char> = itr.next().unwrap().chars().collect();

    let mut ops = Vec::new();
    let mut num = Vec::new();
    let mut now = 0;
    let mut ok = false;
    let mut head = false;
    let n = s.len();
    for i in 0..n {
        if s[i] == '+' || s[i] == '-' {
            ops.push(s[i]);
            if i == 0 {
                head = true;
            }
            if ok {
                num.push(now);
                now = 0;
                ok = false;
            }
        } else {
            ok = true;
            now = now * 10 + (s[i] as u8 - '0' as u8) as i64;
        }
    }
    num.push(now);
    let mut ans = 0;
    match ops.len() {
        1 => {
            ans = if ops[0] == '+' {
                num[0] - num[1]
            } else {
                num[0] + num[1]
            }
        }
        2 => {
            ans = if head {
                if ops[1] == '+' {
                    -num[0] - num[1]
                } else {
                    -num[0] + num[1]
                }
            } else {
                if ops[0] == '+' {
                    num[0] + num[1]
                } else {
                    num[0] - num[1]
                }
            }
        }
        3 => {
            ans = if ops[1] == '+' {
                -num[0] + num[1]
            } else {
                -num[0] - num[1]
            }
        }
        _ => {}
    }
    println!("{}", ans);
}
0