結果

問題 No.708 (+ー)の式
ユーザー ajinoriajinori
提出日時 2018-06-29 23:26:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,363 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 164,768 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-13 15:41:44
合計ジャッジ時間 2,209 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const double inf = 900900900100.0;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    string s;
    cin >> s;
    int res = 0;
    bool flag = false;
    rep(i,s.size()) {
        if(s[i] == '-') flag = true;
        if(s[i] == '+') flag = false;
        if(s[i]>'0' && s[i]<'9'){
            if(flag) res-=s[i]-'0';
            else res += s[i]-'0';
            flag = false;
        }
        if (s[i] == '('){
            int tmp=0;
            if(s[i+2]=='+'){ tmp = (s[i+1]-'0')+(s[i+3]-'0'); }

            if(s[i+2]=='-'){ tmp = (s[i+1]-'0')-(s[i+3]-'0'); }

            if(flag) res-=tmp;
            else res += tmp;
            flag = false;
            i+=4;
        }
    }
    cout << res << endl;
    return 0;
}
0