ProgramAlgTrain/20240823/十四届蓝桥比赛/简单算术题.cpp

35 lines
603 B
C++
Raw Normal View History

2024-09-17 10:55:15 +00:00
#include<iostream>
2024-09-17 12:04:21 +00:00
#include<stack>
2024-08-23 14:19:02 +00:00
using namespace std;
typedef long long ll;
stack<ll> s;
int main(){
int i;
cin>>i;
char f;
s.push(i);
while(cin>>f){
cin>>i;
if(f=='+'){
s.push(i);
}else if(f=='-'){
s.push(-i);
}else if(f=='*'){
int h = s.top();
s.pop();
s.push(h*i);
}else{
int h = s.top();
s.pop();
s.push(h/i);
}
}
int ans = 0;
while(s.empty()==false){
ans+=s.top();
s.pop();
}
cout<<ans<<endl;
}