#include <stdio.h>
#include <string.h>
#include <stdlib.h>


#define Max 256


struct Stack
{
	int X[Max];
	int top;
};

typedef struct Stack STT;


int IsEmpty( STT * pst );
int IsFull( STT * pst );
int Pop( STT * pst );
void Push( STT * pst,int x );

int Add(int x,int y);
int Sub(int x,int y);
int Mult(int x,int y);
int Div(int x,int y);



//دالة قراءة التعبير الرياضي حرفا حرفا
void ReadExpration_1();






int main()
{

	ReadExpration_1();
	


	return  0;
}



//دالة قراءة التعبير الرياضي حرفا حرفا
void ReadExpration_1()
{

	STT  S;
	char string[Max],ch;
	int i;
	int X,Y,T;

	S.top = -1;
	i = 0;

	//اقرأ السلسلة النصية حرفا حرفا
	while( ch != '\n' )
	{
		ch = getchar();
		string[i] = ch;
		i++;
	}



	string[i] = '\0';

	for( int j=0; j<i; j++)
	{
		if( string[j] >=48 && string[j] <= 57 )
		{
			//عملية تحويل الحرف إلى عدد
			int x = atoi(&string[j]);
			printf("\n push(%d)",x);
			Push(&S,x);
		}
		else if( string[j] == '+' )
		{
			X = Pop(&S);
			Y = Pop(&S);
			//T = X + Y;
			T = Add(Y,X);
			Push(&S,T);
			printf("\n %d = pop()\n %d = pop()\n %d = Add(%d,%d)\n push(%d)",X,Y,T,Y,X,T);
		}
		else if( string[j] == '-' )
		{
			X = Pop(&S);
			Y = Pop(&S);
			//T = X - Y;
			T = Sub(Y,X);
			Push(&S,T);
			printf("\n %d = pop()\n %d = pop()\n %d = Sub(%d,%d)\n push(%d)",X,Y,T,Y,X,T);
		}
		else if( string[j] == '*' )
		{
			X = Pop(&S);
			Y = Pop(&S);
			//T = X * Y;
			T = Mult(Y,X);
			Push(&S,T);
			printf("\n %d = pop()\n %d = pop()\n %d = Mult(%d,%d)\n push(%d)",X,Y,T,Y,X,T);
		}
		else if( string[j] == '/' )
		{
			X = Pop(&S);
			Y = Pop(&S);
			//T = X / Y;
			T = Div(Y,X);
			Push(&S,T);
			printf("\n %d = pop()\n %d = pop()\n %d = Div(%d,%d)\n push(%d)",X,Y,T,Y,X,T);
		}		

		
	}

	printf("\n\n\n Good Bay \n\n\n Khaled Alharbi \n\n\n");	
	

}


int IsEmpty( STT * pst )
{
	if( pst->top == -1 )
		return 1;
	else
		return 0;
}


int IsFull( STT * pst )
{
	if( pst->top == Max-1 )
		return 1;
	else
		return 0;
}

int Pop( STT * pst )
{
	if( IsEmpty(pst) )
	{
		printf("\n Stack is Empty \n");
		exit(1);
	}
	else
		return pst->X[pst->top--];

}

void Push( STT * pst,int x )
{
	if( IsFull(pst) )
		printf("\n Stack is Full \n");
	else
		pst->X[++pst->top] = x;

}

int Add(int x,int y)
{
	return x+y;
}

int Sub(int x,int y)
{
	return x-y;
}

int Mult(int x,int y)
{
	return x*y;
}

int Div(int x,int y)
{
	if( y > 0 )
	{
		return x/y;
	}
	else
	{
		printf("\n Y = %d < 0 ",y);
		return -1;
	}
}

