代码:
#include <iostream>
#include <stack>
#include <cmath>
using namespace std;
stack<int> m;
int main(){
char temp;
int temp1=0,shu1,shu2;
while(cin>>temp && temp!='@'){
if(temp>='0' && temp<='9'){
temp1*=10;
temp1+=(temp-'0');
}else if(temp=='.'){
m.push(temp1);
temp1=0;
}else if(temp=='+'){
shu1=m.top();
m.pop();
shu2=m.top();
m.pop();
m.push(shu1+shu2);
}else if(temp=='*'){
shu1=m.top();
m.pop();
shu2=m.top();
m.pop();
m.push(shu1*shu2);
}else if(temp=='-'){
shu1=m.top();
m.pop();
shu2=m.top();
m.pop();
m.push(abs(shu1-shu2));
}else if(temp=='/'){
shu1=m.top();
m.pop();
shu2=m.top();
m.pop();
m.push(shu1/shu2);
}
}
cout<<m.top();
}
我下载了第二个数据,自己手算是3,程序输出也是3,可答案是7,十分不解