Problem Description
对于一个基于二元运算符的算术表达式,转换为对应的后缀式,并输出之。
Input
输入一个算术表达式,以‘#’字符作为结束标志。
Output
输出该表达式转换所得到的后缀式。
Example Input
a*b+(c-d/e)*f#
Example Output
ab*cde/-f*+
Hint
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int i,j,n,top=0;
char g[10000],s;
while(scanf("%c",&s)&&s!='#')
{
if(s>='a'&&s<='z') printf("%c",s);
else if(s==')')
{
while(g[top]!='(')
{
printf("%c",g[top--]);
}
top--;
}
else if(s=='(')
g[++top]=s;
else if(s=='+'||s=='-')
{
while(top>0&&g[top]!='(')
{
printf("%c",g[top--]);
}
g[++top]=s;
}
else if(s=='*'||s=='/')
{
while(top>0&&(g[top]=='*'||g[top]=='/'))
{
printf("%c",g[top--]);
}
g[++top]=s;
}
}
for(i=top;i>0;i--)
printf("%c",g[i]);
return 0;
}