cpp
2025-01-15 21:06:31
发布于:江苏
13阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
stack<int>stk;
char tmp;
int ttmp;
int a,b;
int main(){
while(true){
cin>>tmp;
if(tmp>='0'&&tmp<='9'){
ttmp*=10;
ttmp+=tmp-'0';
}else if(tmp=='.'){
stk.push(ttmp);
ttmp=0;
}else if(tmp=='@'){
cout<<stk.top();
return 0;
}else if(tmp=='+'){
a=stk.top();
stk.pop();
b=stk.top();
stk.pop();
stk.push(a+b);
}else if(tmp=='-'){
a=stk.top();
stk.pop();
b=stk.top();
stk.pop();
stk.push(b-a);
}else if(tmp=='*'){
a=stk.top();
stk.pop();
b=stk.top();
stk.pop();
stk.push(a*b);
}else if(tmp=='/'){
a=stk.top();
stk.pop();
b=stk.top();
stk.pop();
stk.push(b/a);
}
}
return 0;
}
这里空空如也
有帮助,赞一个