結果

問題 No.222 引き算と足し算
ユーザー CleyLCleyL
提出日時 2020-03-03 13:29:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 620 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 71,884 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 23:54:59
合計ジャッジ時間 2,080 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 WA -
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 WA -
testcase_33 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stack>
using namespace std;
int main(){
    string s;cin>>s;
    stack<int> nya;
    int nw = 1;
    bool num = false;
    char ke = 'e';
    for(int i = 0; s.size() > i; i++){
        if(!num && s[i] == '+')continue;
        else if(!num && s[i] == '-')nw *= -1;
        else if(!num)nw *= s[i]-'0',num = true;
        else if('0' <= s[i] && s[i] <= '9')nw = nw*10+s[i]-'0';
        else{
            nya.push(nw);
            num = false;
            nw = 1;
            if(s[i] == '+')ke = '-';
            else ke = '+';
        }
    }
    cout << nya.top()+(ke=='+'?nw:-nw) << endl;
}
0