#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
int S[10];
struct stacknode{
int item;
stacknode *next;
};
struct stack{
stacknode *top;
};
void construct(stack *s){
s=(stack *)malloc (sizeof(stack));
s->top=NULL;
}
int stackempty(stack *s){
return (s->top==NULL);
}
void stackinsert(char x, stack *s){
stacknode *temp;
temp=(stacknode *) malloc (sizeof(stacknode));
temp->next=s->top;
s->top=temp;
temp->item=x;
}
int stackpop (stack *A){
int x;
stacknode *temp;
temp=A->top;
A->top=temp->next;
x=temp->item;
free(temp);
return x;
}
int kiemtra(char s){
if (s=='+'||s=='-'||s=='*') return 1;
else return 0;
}
int culation(int a,int b,char s1){
int ans;
switch (s1){
case '+': ans=a+b; break;
case '-': ans=a-b; break;
case '*': ans=a*b; break;
}
return ans;
}
int eval(char *s,stack *A){
int n=strlen(s); int ans;
int first, second;
for (int i=0;i<n;i++){
if (kiemtra(s[i])) {
second=stackpop(A); first=stackpop(A);
ans=culation(first,second,s[i]);
stackinsert(ans,A);
}
else stackinsert(s[i],A);
}
return stackpop(A);
}

void display(stack *s){
stacknode *temp;
temp=(stacknode *)malloc (sizeof(stacknode));
temp=s->top;
do{
printf("%2d ",temp->item);
temp=temp->next;
} while (temp!=NULL);
}
int main(){
char s[100];
printf("nhap xau s:");
gets(s);
int n=strlen(s);
for (int i=0;i<n;i++){
int m=s[i];
while(48<=m&&m<=57){
m=m-48;
s[i]=m;
}
}
stack *A;
A=(stack *) malloc (sizeof(stack));
A->top=NULL;
int x=eval(s,A);
printf("\n gia tri cua bieu thuc : %i",x);
getch();
return 0;
}