#include<stdio.h>
#include<stdlib.h>
#define MAX 50
typedef struct
{
char data[MAX];
int top;
}stack;
typedef struct
{
float data[MAX];
int top;
}fstack;stack* create()
{
stack *s;
s=malloc(sizeof(stack));
s->top=-1;
return s;
}
fstack* fcreate()
{
fstack *s;
s=malloc(sizeof(fstack));
s->top=-1;
return s;
}
int getstack(stack *s,char x )
{
if(s->top==MAX-1)
return 0;
s->top++;
s->data[s->top]=x;
return 1;
}
int fgetstack(fstack *s,float x )
{
if(s->top==MAX-1)
return 0;
s->top++;
s->data[s->top]=x;
return 1;
}
int outstack(stack *s,char *x)
{
if(s->top==-1)
return 0;
*x=s->data[s->top];
s->top--;
return 1;
}
int foutstack(fstack *s,float *x)
{
if(s->top==-1)
return 0;
*x=s->data[s->top];
s->top--;
return 1;
}
char readstack(stack *s)
{
char x;
if(s->top==-1)
return '0';
x=s->data[s->top];
return x;
}
float freadstack(fstack *s)
{
float x;
if(s->top==-1)
return '0';
x=s->data[s->top];
return x;
}
char bi(char x1,char x2)//>出站;<进站;
{
switch(x1)
{
case '(':
switch(x2)
{
case ')':
return '>';
break;
default:
return '<';
break;
}
break;
case '+':
case '-':
switch(x2)
{
case '(':
return '<';
break;
case '*':
return '<';
break;
case '/':
return '<';
break;
default :
return '>';
}break;
case '*':
case '/':
switch(x2)
{
case '(':
return '<';
break;
default :
return '>';
}break;
}
return '0';
}
float jisuan(float x1,char a,float y1)
{
switch(a)
{
case '+':
return x1+y1;
case '-':
return x1-y1;
case '*':
return x1*y1;
case '/':
return x1/y1;
}
return 0;
}
float fun1(char a[])
{
float b,b1,b2,b3;
int i=0;
char x,x1,ch;
stack *s=create();
fstack *p=fcreate();
getstack(s,'(');
ch=a[0];
while(ch!='#')
{
switch(ch)
{
case '(':
getstack(s,'(');
break;
case ')':
while(readstack(s)!='(')
{
outstack(s,&x);
foutstack(p,&b1);
foutstack(p,&b2);
b3=jisuan(b1,x,b2);
fgetstack(p,b3);
}
outstack(s,&x);
break;
case '+':
case '-':
x=readstack(s);
x1=bi(x,ch);
if(x1=='<')
getstack(s,ch);
else
{
while(readstack(s)!='(')
{
outstack(s,&x);
foutstack(p,&b1);
foutstack(p,&b2);
b3=jisuan(b1,x,b2);
fgetstack(p,b3);
}
getstack(s,ch);
}
break;
case '*':
case '/':
x=readstack(s);
x1=bi(x,ch);
if(x1=='<')
getstack(s,ch);
else
{
while(readstack(s)!='('&&readstack(s)!='+'&&readstack(s)!='-')
{
outstack(s,&x);
foutstack(p,&b1);
foutstack(p,&b2);
b3=jisuan(b1,x,b2);
fgetstack(p,b3);
}
getstack(s,ch);
}
break;
default :
if(ch>='0'&&ch<='9')
{
fgetstack(p,(ch-'0'));
printf("%f\n",freadstack(p));
}
break;
}
ch=a[++i];
}
while(readstack(s)!='(')
{
outstack(s,&x);
foutstack(p,&b1);
foutstack(p,&b2);
b3=jisuan(b1,x,b2);
fgetstack(p,b3);
}
b=freadstack(p);
return b;
}
int main()
{
int i;
float b;
char a[MAX];
for(i=0;;i++)
{
scanf("%c",&a[i]);
if(a[i]=='#')
break;
}
b=fun1(a);
printf("====%f\n",b);
}