1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include <iostream>
using namespace std;
const int N = 1e4 + 10;
int stk[N];
char op[N];
int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>op; int t = 0, index = 0; for(int i = 0; op[i] != '@'; i++){ if(op[i] >= '0' && op[i] <= '9'){ index = index * 10 + op[i] - '0'; } else if(op[i] == '.'){ stk[++t] = index; index = 0; } else if(op[i] == '+'){ stk[t - 1] = stk[t - 1] + stk[t]; t--; } else if(op[i] == '-'){ stk[t - 1] = stk[t - 1] - stk[t]; t--; } else if(op[i] == '*'){ stk[t - 1] = stk[t - 1] * stk[t]; t--; } else if(op[i] == '/'){ stk[t - 1] = stk[t - 1] / stk[t]; t--; } else if(op[i] == '@') break; } cout<<stk[1]<<endl; return 0; }
|