/*
*@author: percation
*#time:2021.04.22
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
stack<int> st;
stack<char> op;
int num;
char c;
for(int i = 0; i < n; i++){
cin >> num;
st.push(num);
}
for(int i = 0; i < n - 1; i++){
cin >> c;
op.push(c);
}
int ans = 0;
char oop;
while(!op.empty() || st.size() != 1){
int a = st.top();//n1
st.pop();
int b = st.top();//n2;
st.pop();
if(!op.empty()){
oop = op.top();
op.pop();
}
if(oop == '+'){
ans = b + a;
st.push(ans);
}
if(oop == '-'){
ans = b - a;
st.push(ans);
}
if(oop == '*'){
ans = b * a;
st.push(ans);
}
if(oop == '/'){
if(a != 0){
ans = b / a;
st.push(ans);
}
else{
cout << "ERROR: " << b <<"/0" << endl;
return 0;
}
}
}
cout << st.top() << endl;
return 0;
}
L2-033 简单计算器 (25 point(s))
最新推荐文章于 2024-09-25 21:54:15 发布