Problem Description
对于一个基于二元运算符的算术表达式,转换为对应的后缀式,并输出之。
Input
输入一个算术表达式,以‘#’字符作为结束标志。
Output
输出该表达式转换所得到的后缀式。
Example Input
a*b+(c-d/e)*f#
Example Output
ab*cde/-f*+
Hint
Author
#include <stdio.h>
#include<math.h>
#include <stack>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main()
{
stack <char> p;
char kk;
while(kk=getchar())
{
if(kk>='a'&&kk<='z'||kk>='A'&&kk<='Z')
{
printf("%c", kk);
}
else if(kk=='+'||kk=='-')
{
while(!p.empty()&&(p.top()=='*'||p.top()=='/'))
{
printf("%c", p.top());
p.pop();
}
p.push(kk);
}
else if(kk=='*'||kk=='/')
{
p.push(kk);
}
else if(kk=='(')
{
p.push(kk);
}
else if(kk==')')
{
while(p.top()!='(')
{
printf("%c", p.top());
p.pop();
}
p.pop();
}
else if(kk=='#')
{
while(!p.empty())
{
printf("%c", p.top());
p.pop();
}
break;
}
}
return 0;
}