#include<iostream>
#include<stdlib.h>
#include<cstring>
using namespace std;
#define Maxsize 10
template <class T>
class Stack
{
public:
Stack()
{
top=-1;
length=0;
}
~Stack() {}
void push(T x);
T pop();
T gettop();
int Empty();
int Size()
{
return length;
}
private:
T Date[Maxsize];
int top;
int length;
};
template <class T>
void Stack<T>::push(T x)
{
if(top==Maxsize-1)
{
throw"栈满无法入栈";
}
Date[++top]=x;
length++;
}
template <class T>
T Stack<T>::pop()
{
if(top==-1)
{
throw"栈空无法出栈";
}
T x=Date[top--];
return x;
}
template <class T>
T Stack<T>::gettop()
{
if(top==-1)
{
throw"栈空";
}
return Date[top];
}
template <class T>
int Stack<T>::Empty()
{
if(top==-1)
{
return 1;
}
else
{
return 0;
}
}
int Hzoper(string c[],int n){
Stack<int>s;
for(int i=0;i<=n;i++){
if(c[i]=="#"){
return s.gettop();
}
if(c[i]=="+"||c[i]=="-"||c[i]=="*"||c[i]=="/"){
int l,r,sum;
r=s.pop();
l=s.pop();
char ch[1],cc;
strcpy(ch,c[i].c_str());
cc=ch[0];
switch(cc){
case '+':sum=l+r;
break;
case '-':sum=l-r;
break;
case '*':sum=l*r;
break;
case '/':sum=l/r;
}
s.push(sum);
}
else{
int n=atoi(c[i].c_str());
s.push(n);
}
}
}
int main()
{
string c[20],ch;
int i;
for(i=0;;i++){
cin>>ch;
if(ch=="#"){
c[i]=ch;
break;
}
c[i]=ch;
}
int n=Hzoper(c,i);
cout<<n;
}
#include<stdlib.h>
#include<cstring>
using namespace std;
#define Maxsize 10
template <class T>
class Stack
{
public:
Stack()
{
top=-1;
length=0;
}
~Stack() {}
void push(T x);
T pop();
T gettop();
int Empty();
int Size()
{
return length;
}
private:
T Date[Maxsize];
int top;
int length;
};
template <class T>
void Stack<T>::push(T x)
{
if(top==Maxsize-1)
{
throw"栈满无法入栈";
}
Date[++top]=x;
length++;
}
template <class T>
T Stack<T>::pop()
{
if(top==-1)
{
throw"栈空无法出栈";
}
T x=Date[top--];
return x;
}
template <class T>
T Stack<T>::gettop()
{
if(top==-1)
{
throw"栈空";
}
return Date[top];
}
template <class T>
int Stack<T>::Empty()
{
if(top==-1)
{
return 1;
}
else
{
return 0;
}
}
int Hzoper(string c[],int n){
Stack<int>s;
for(int i=0;i<=n;i++){
if(c[i]=="#"){
return s.gettop();
}
if(c[i]=="+"||c[i]=="-"||c[i]=="*"||c[i]=="/"){
int l,r,sum;
r=s.pop();
l=s.pop();
char ch[1],cc;
strcpy(ch,c[i].c_str());
cc=ch[0];
switch(cc){
case '+':sum=l+r;
break;
case '-':sum=l-r;
break;
case '*':sum=l*r;
break;
case '/':sum=l/r;
}
s.push(sum);
}
else{
int n=atoi(c[i].c_str());
s.push(n);
}
}
}
int main()
{
string c[20],ch;
int i;
for(i=0;;i++){
cin>>ch;
if(ch=="#"){
c[i]=ch;
break;
}
c[i]=ch;
}
int n=Hzoper(c,i);
cout<<n;
}