結果
| 問題 | No.1135 RPN |
| ユーザー |
|
| 提出日時 | 2020-08-01 06:50:20 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 784 bytes |
| 記録 | |
| コンパイル時間 | 504 ms |
| コンパイル使用メモリ | 90,496 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-11 23:06:46 |
| 合計ジャッジ時間 | 1,491 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#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;
}