結果

問題 No.1135 RPN
ユーザー oooooba
提出日時 2021-06-16 21:35:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 1,185 ms
コンパイル使用メモリ 119,680 KB
最終ジャッジ日時 2025-01-22 08:32:10
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <optional>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int32_t n;
    cin >> n;
    stack<int32_t> stk;
    for (auto i = 0; i < n; ++i) {
        string a;
        cin >> a;
        if (a == "+") {
            auto y = stk.top();
            stk.pop();
            auto x = stk.top();
            stk.pop();
            stk.push(x + y);
        } else if (a == "-") {
            auto y = stk.top();
            stk.pop();
            auto x = stk.top();
            stk.pop();
            stk.push(x - y);
        } else {
            int32_t x = stoi(a);
            stk.push(x);
        }
    }
    cout << stk.top() << endl;
    return 0;
}
0