#include <stdio.h>
#include <string.h>
char stack[10000];
int top;
int ch(char c) //此函数分出来符号的等级
{
if(c=='+'||c=='-')
return 1;
if(c=='*'||c=='/')
return 2;
if(c=='(')
return 3;
if(c==')')
return 4;
return 0;
}
int main()
{
char c;
top=0;
while(scanf("%c",&c)!=EOF&&c!='#')
{
if(c<='z'&&c>='a') //如果是字母直接输出
printf("%c",c);
else
{
if(top==0) //如果是第一个字符就进栈
{
top++;
stack[top]=c;
}
else if(ch(c)>ch(stack[top])) //即将入栈的符号与栈顶符号相比较
{
if(ch(c)==4) //如果是右括号,就将左括号之上的全部输出
{
while(stack[top]!='(')
{
printf("%c",stack[top]);
top--;
}
top--;
}
else //否则进栈
{
top++;
stack[top]=c;
}
}
else
{
if(stack[top]!='(') //如果不是左括号,那么先输出栈顶符号,再讲输入的符号入栈
{
printf("%c",stack[top]);
stack[top]=c;
}
else //如果是左括号,则入栈
{
top++;
stack[top]=c;
}
}
}
}
while(top) //最后,将栈里边的符号全部输出
{
printf("%c",stack[top]);
top--;
}
}