結果

問題 No.708 (+ー)の式
ユーザー BantakoBantako
提出日時 2018-07-09 09:56:54
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,561 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 174,700 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 08:32:10
合計ジャッジ時間 2,409 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 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,cst2;
    deque<int>  nst,nst2;
    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 = nst2.front();
                nst2.pop_front();
                int b = nst2.front();
                nst2.pop_front();
                if(cst2.front() == '+'){
                    nst2.push_front(a + b);              
                }else{
                    nst2.push_front(a - b);
                }
                cst2.pop_front();
            }
            nst.push_back( nst2.back() );
            nst2.pop_back();
            cnt = 0;
        }else if(c == '+' || c == '-'){
            
            if(flag){
                cst2.push_back(c);
                cnt++;
            }else{
                cst.push_back(c);
            }
        }else{
            if(!flag)nst.push_back(c - '0');
            else     nst2.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