P1449后缀表达式,一输入就蹦
#include<bits/stdc++.h>
using namespace std;
char s;
int a[55];
int top;
int x,y,z;
void fufu(int fu)
{
x=a[fu];
a[fu]=0;
fu--;
y=a[fu];
a[fu]=0;
fu--;
top=fu+1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(;;)
{
cin>>s;
if(s=='@')break;
if(s>=48 && s<=57)a[top]=(int)s-48,top++;
if(s=='-')
{
fufu(top-1);
z=y-x;
a[top]=z;
cout<<"fufu:"<<x<<" "<<y<<" "<<a[top]<<top<<endl;
top++;
}
else if(s=='+')
{
fufu(top-1);
z=y+x;
a[top]=z;cout<<"fufu:"<<x<<" "<<y<<" "<<a[top]<<top<<endl;
top++;
}
else if(s=='*')
{
fufu(top-1);
z=y*x;
a[top]=z;cout<<"fufu:"<<x<<" "<<y<<" "<<a[top]<<top<<endl;
top++;
}
else if(s=='/')
{
fufu(top-1);
z=y/x;
a[top]=z;cout<<"fufu:"<<x<<" "<<y<<" "<<a[top]<<top<<endl;
top++;
}
}
cout<<a[top-1];
return 0;
}