結果
問題 |
No.1135 RPN
|
ユーザー |
![]() |
提出日時 | 2021-01-31 16:34:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 694 bytes |
コンパイル時間 | 1,713 ms |
コンパイル使用メモリ | 198,816 KB |
最終ジャッジ日時 | 2025-01-18 10:17:43 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(ll i=0;i<n;i++) int main(){ stack<int>sta; int n; cin>>n; string s; int a,b,x; for(int i=0;i<n;i++){ x=0; a=0; b=0; cin>>s; if(s=="+"){ a=sta.top(); sta.pop(); b=sta.top(); sta.pop(); x=a+b; sta.push(x); continue; } if(s=="-"){ b=sta.top(); sta.pop(); a=sta.top(); sta.pop(); x=a-b; sta.push(x); continue; } for(int j=0;j<s.length();j++){ x+=s.at(j)-'0'; if(j != s.length()-1) x*=10; } sta.push(x); } x=sta.top(); cout<<x<<endl; return 0; }