#include
#include
typedef struct huozhui{
char c;
struct huozhui next;
}huozhui;
void push(huozhui *L,char x)
{
huozhui *p=(huozhui *)malloc(sizeof(huozhui));
p->c=x;
p->next=L->next;
L->next=p;
}
int isoperator(char x)
{
if(x=='+'||x=='-'||x==''||x=='/'||x=='('||x==')')
return 0;
else
return 1;
}
int bijiao(char x)
{
switch(x)
{
case '+':
case '-':
return 1;
case '*':
case '/':
return 2;
}
return -1;
}
int isempty(huozhui *L)
{
return L->next==NULL;
}
void pop(huozhui *L)
{
if(L->next==NULL)
return ;
else
{
huozhui *p;
p=L->next;
L->next=p->next;
free(p);
}
}
char top(huozhui *L)
{
if(L->next==NULL)
return 0;
else
return L->next->c;
}
int main()
{
huozhui *L=(huozhui *)malloc(sizeof(huozhui));
L->next=NULL;
char s[100],key[200];
gets(s);
int i,k=0;
for(i=0;s[i]!='\0';i++)
{
if(isoperator(s[i])==1)
{
key[k++]=s[i];
}
else
{
if(isempty(L))
{
push(L,s[i]);
}
else
{
if(s[i]==')')
{
while(!isempty(L)&&top(L)!='(')
{
key[k++]=top(L);
pop(L);
}
pop(L);
}
else
{
if(s[i]=='(')
push(L,s[i]);
else
{
while(bijiao(top(L))>=bijiao(s[i])&&!isempty(L))
{
key[k++]=top(L);
pop(L);
}
push(L,s[i]);
}
}
}
}
}
huozhui *p=L->next;
while(p!=NULL)
{
key[k]=p->c;
p=p->next;
k++;
}
key[k]='\0';
for(i=0;i<k;i++)
{
if(i!=0)
printf(" ");
printf("%c",key[i]);
}
puts("");
return 0;
}