简单的计算后缀表达式的值,利用stack
#include<iostream>
#include<stack>
using namespace std;
int main()
{
string s;
cin>>s;
stack<int> S;
int i=0;
while(i<s.length())
{
if(s[i]>='0'&&s[i]<='9')
{
int a=0;
while(s[i]!='.')
{
a=a*10+(s[i]-'0');
i++;
}
S.push(a);
}
if(s[i]!='@')
{
if(s[i]=='-')
{
int a;int b;
b=S.top();S.pop();
a=S.top();S.pop();
S.push(a-b);
}
if(s[i]=='+')
{
int a;int b;
b=S.top();S.pop();
a=S.top();S.pop();
S.push(a+b);
}
if(s[i]=='*')
{
int a;int b;
b=S.top();S.pop();
a=S.top();S.pop();
S.push(a*b);
}
if(s[i]=='/')
{
int a;int b;
b=S.top();S.pop();
a=S.top();S.pop();
S.push(a/b);
}
i++;
}
else
break;
}
cout<<S.top()<<endl;
return 0;
}