答案
2025-02-15 19:43:28
发布于:北京
9阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
int main(){
stack<int> s;
string a;
cin >> a;
int len = a.size();
for(int i=0;i<len;i++ ) {
if(a[i]>='0' and a[i]<='9'){
int sum=0;
while(a[i]!='.'){
sum=sum10+(a[i]-'0');
i++;
}
s.push(sum);
}
if(a[i]'+' || a[i]'-' || a[i]=='' || a[i]'/' ){
int x1=0,x2=0;
x1=s.top();
s.pop();
x2=s.top();
s.pop();
if(a[i]'+'){
s.push(x2+x1);
}
if(a[i]'-'){
s.push(x2-x1);
}
if(a[i]''){
s.push(x2x1);
}
if(a[i]=='/'){
s.push(x2/x1);
}
}
}
cout<<s.top();
return 0;
}
这里空空如也
有帮助,赞一个