#include
#include
#include
typedef struct stacke* stack;
struct stacke {
char* chy;
int tope;
};
stack creat(int);
void pop(int, stack);//入栈
void top(stack);//出zhan
void prin(stack);
int main()
{
char ch;
stack st1, st2;
st1 = creat(100); st2 = creat(100);
while (1)
{
scanf_s("%c", &ch, sizeof(ch));
if (isdigit(ch))
{
pop(ch, st1);
}
else if (ch != '#')
{
if (st2->tope == -1)
{
pop(ch, st2);
}
else
{
if (ch == '+' || ch == '-')
{
while (st2->tope != -1 && st2->chy[st2->tope] != '(')
{
pop(st2->chy[st2->tope], st1); top(st2);
}
pop(ch, st2);
}
else if (ch == '*' || ch == '/')
{
while (st2->chy[st2->tope] != '+' && st2->chy[st2->tope] != '-')
{
if (st2->chy[st2->tope] == '(')
{
pop(ch, st2); break;
}
pop(st2->chy[st2->tope], st1); top(st2);
}
pop(ch, st2);
}
else if (ch == '(') pop(ch, st2);
else if (ch == ')')
{
while (st2->chy[st2->tope] != '(')
{
pop(st2->chy[st2->tope], st1); top(st2);
}
top(st2);
}
}
}
else
{
while (st2->tope != -1)
{
top(st2); pop(st2->chy[st2->tope + 1], st1);
}
break;
}
}
prin(st1);
return 0;
}
void pop(int n, stack s)
{
s->chy[++s->tope] = n;
}
void top(stack s)
{
s->tope--;
}
void prin(stack s)
{
int i = 0;
while (i != s->tope + 1)
{
printf("%c ", s->chy[i++]);
}
}
stack creat(int a)
{
stack s;
s = (stack)malloc(sizeof(stack));
s->chy = (char*)malloc(sizeof(char*) * a);
s->tope = -1;
return s;
}