結果

問題 No.708 (+ー)の式
ユーザー lunnearlunnear
提出日時 2018-11-27 16:20:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 901 bytes
コンパイル時間 839 ms
コンパイル使用メモリ 58,172 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 23:09:08
合計ジャッジ時間 1,220 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <stack>

int main()
{
    char s[101];
    std::cin >> s;
    
    int ans = 0;
    int temp = 0;
    int sign = 0;
    int tsign = 0;

    for(int i = 0; s[i]; i++)
    {
        if((s[i] > '0') && (s[i] < '9'))
            s[i] -= '0';
            
        if(s[i] <= 9)
        {
            switch(sign)
            {
                case  0: ans  = s[i]; break;
                case  1: ans += s[i]; break;
                case -1: ans -= s[i]; break;
            }
            sign = 0;
        }
        if(s[i] == '+')
            sign = 1;
        if(s[i] == '-')
            sign = -1;
        
        if(s[i] == '(')
        {
            temp = ans;
            tsign = sign;
            sign = 0;
        }
        if(s[i] == ')')
        {
            ans = temp + (tsign * ans);
        }
    }

    
    std::cout << ans << std::endl;
    
    return 0;
}
0