#include<iostream>
#include<cstring>
#include<cstdlib>
using namespace std;
class stack
{ public:
char arr[50];
int k,top,arr2[50],c[2];
int pop();
void push(int c);
};
void stack::push(int c)
{arr2[++top]=c;
}
int stack::pop()
{c[k]=arr2[top--];
}
int main()
{stack s;
s.top=-1;
int i,j,z,x;
char c2;
cin.getline(s.arr,30);
j=strlen(s.arr);
for(i=0;i<j;i++)
{if(s.arr[i]=='-' || s.arr[i]=='+' || s.arr[i]=='*' || s.arr[i]=='/')
{for(s.k=0;s.k<2;s.k++)
s.pop();
c2=s.arr[i];
switch(c2)
{case '-':z=s.c[1]-s.c[0];
break;
case '+':z=s.c[1]+s.c[0];
break;
case '*':z=s.c[1]*s.c[0];
break;
case '/':z=s.c[1]/s.c[0];
break;
} s.push(z);
}
else
{x=s.arr[i];
x-=48;s.push(x);
}
}
cout<<s.arr2[s.top];
}
#include<cstring>
#include<cstdlib>
using namespace std;
class stack
{ public:
char arr[50];
int k,top,arr2[50],c[2];
int pop();
void push(int c);
};
void stack::push(int c)
{arr2[++top]=c;
}
int stack::pop()
{c[k]=arr2[top--];
}
int main()
{stack s;
s.top=-1;
int i,j,z,x;
char c2;
cin.getline(s.arr,30);
j=strlen(s.arr);
for(i=0;i<j;i++)
{if(s.arr[i]=='-' || s.arr[i]=='+' || s.arr[i]=='*' || s.arr[i]=='/')
{for(s.k=0;s.k<2;s.k++)
s.pop();
c2=s.arr[i];
switch(c2)
{case '-':z=s.c[1]-s.c[0];
break;
case '+':z=s.c[1]+s.c[0];
break;
case '*':z=s.c[1]*s.c[0];
break;
case '/':z=s.c[1]/s.c[0];
break;
} s.push(z);
}
else
{x=s.arr[i];
x-=48;s.push(x);
}
}
cout<<s.arr2[s.top];
}
No comments:
Post a Comment