結果

問題 No.708 (+ー)の式
ユーザー BantakoBantako
提出日時 2018-07-09 09:48:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,314 bytes
コンパイル時間 3,106 ms
コンパイル使用メモリ 174,020 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 08:31:18
合計ジャッジ時間 2,282 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    8 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;

main(){
    string S;
    cin >> S;
    deque<char> cst;
    deque<int>  nst;
    bool flag = 0;
    int cnt = 0;
    for(char c:S){
        if(c == '(')flag = 1;
        else if(c == ')'){
            flag = 0;
            rep(i,0,cnt){                    
                int a = nst.front();
                nst.pop_front();
                int b = nst.front();
                nst.pop_front();
                if(cst.front() == '+'){
                    nst.push_front(a + b);              
                }else{
                    nst.push_front(a - b);
                }
                cst.pop_front();
            }
            cnt = 0;
        }else if(c == '+' || c == '-'){
            cst.push_back(c);
            if(flag)cnt++;
        }else{
            nst.push_back(c - '0');
        }
    }
    while(nst.size() > 1){
        int a = nst.front();
        nst.pop_front();
        int b = nst.front();
        nst.pop_front();
        if(cst.front() == '+'){
            nst.push_front(a + b);              
        }else{
            nst.push_front(a - b);
        }
        cst.pop_front();
    }
    cout << nst.front() << endl;
}
0