結果
問題 |
No.1135 RPN
|
ユーザー |
![]() |
提出日時 | 2020-09-22 08:42:58 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 508 bytes |
コンパイル時間 | 1,883 ms |
コンパイル使用メモリ | 172,320 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-25 19:01:56 |
合計ジャッジ時間 | 2,599 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ul = unsigned long; using ull = unsigned long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; stack<ll> st; for (int i = 0; i < n; ++i) { string s; cin >> s; if (s == "+" || s == "-") { ll b = st.top(); st.pop(); ll a = st.top(); st.pop(); if (s == "-") b *= -1; st.push(a + b); } else st.push(stoll(s)); } cout << st.top() << "\n"; return 0; }