#include<stdio.h>
int fun(char str)
{
if(str=='+'||str=='-') return 1;
if(str=='*'||str=='/') return 2;
if(str=='(') return 3;
if(str==')') return 4;
}
int main()
{
char opnd[100];
char oprt[100],str;
int i=0,j=0;
while(scanf("%c",&str),str!='#')
{
if(str>='a'&&str<='z')
printf("%c",str);
else
{
if(j==0) oprt[++j]=str;
else
{
if(fun(str)>fun(oprt[j]))
{
if(fun(str)==4)
{
while(oprt[j]!='(')
printf("%c",oprt[j--]);

j--;
}
else
oprt[++j]=str;
}

else
{

if(oprt[j]!='(')
{
printf("%c",oprt[j]);
oprt[j]=str;
}
else oprt[++j]=str;
}
}
}
}
while(j!=0)
{
printf("%c",oprt[j--]);
}return 0;
}

相关文章:

  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
相关资源
相似解决方案