結果
| 問題 |
No.1135 RPN
|
| ユーザー |
kyo1
|
| 提出日時 | 2020-07-31 02:55:07 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 684 bytes |
| コンパイル時間 | 2,221 ms |
| コンパイル使用メモリ | 199,032 KB |
| 最終ジャッジ日時 | 2025-01-12 08:28:00 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int to_int(string s) {
int res = 0;
for (int i = 0; i < (int)s.size(); i++) {
res = res * 10 + (s[i] - '0');
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
stack<int> st;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
if (s == "+") {
int a = st.top();
st.pop();
int b = st.top();
st.pop();
st.push(a + b);
} else if (s == "-") {
int a = st.top();
st.pop();
int b = st.top();
st.pop();
st.push(b - a);
} else {
st.push(to_int(s));
}
}
cout << st.top() << '\n';
return 0;
}
kyo1