結果

問題 No.708 (+ー)の式
ユーザー BantakoBantako
提出日時 2018-07-09 09:48:01
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,314 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 174,924 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 00:48:02
合計ジャッジ時間 2,171 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 5 WA * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-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