結果

問題 No.1135 RPN
ユーザー Mister
提出日時 2020-08-01 06:50:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 784 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 72,800 KB
最終ジャッジ日時 2025-01-12 12:13:30
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> stk;
    while (n--) {
        std::string s;
        std::cin >> s;

        if (s == "+") {
            int b = stk.back();
            stk.pop_back();
            int a = stk.back();
            stk.pop_back();
            stk.push_back(a + b);

        } else if (s == "-") {
            int b = stk.back();
            stk.pop_back();
            int a = stk.back();
            stk.pop_back();
            stk.push_back(a - b);

        } else {
            stk.push_back(std::stoi(s));
        }
    }

    std::cout << stk.front() << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0