#include
using namespace std;
#include
#include
#include
#include
#include
const int maxn = 100020;
stacknum; //数字栈
stackop; //运算符栈
void eval() //用于中缀表达式计算
{
auto b = num.top(); //考虑运算顺序,先取出来的是第二个运算数
num.pop();
auto a = num.top();
num.pop();
auto c = op.top();
op.pop();
double x = 0;
if (c == '+')x = a + b;
else if (c == '-')x = a - b;
else if (c == '*')x = a * b;
else x = a / b;
num.push(x);
}
bool eval_(char c) //用于后缀表达式
{
auto b = num.top(); //考虑运算顺序,先取出来的是第二个运算数
num.pop();
auto a = num.top();
num.pop();
int x = 0;
if (c == '+')x = a + b;
else if (c == '-')x = a - b;
else if (c == '*')x = a * b;
else {
if (b == 0)
{
cout pr{ {'+',1},{'-',1},{'*',2},{'/',2} }; //定义一个哈希表,存储优先级
for (int i = 0; i = pr[c])//符号栈没空,并且栈顶的运算符优先级大于当前运算符
{
eval(); //操作栈顶的运算符
}
op.push(c); //新的运算符压入栈
}
}
while (op.size()) //把最后剩下的运算符操作完
{
eval();
}
cout 1)
{
cout shu;
stackfu;
unordered_mappr{ {'+',1},{'-',1},{'*',2},{'/',2} }; //定义一个哈希表,存储优先级
for (int i = 0; i = pr[c])//符号栈没空,并且栈顶的运算符优先级大于当前运算符
{
auto temp = fu.top();
fu.pop();
ans += temp;
ans += " ";
}
fu.push(c); //新的运算符压入栈
}
}
while (fu.size()) //把最后剩下的运算符操作完
{
auto temp = fu.top();
fu.pop();
ans += temp;
ans += " ";
}
ans += '#';
return ans;
}
int main()
{
string s;
cin >> s;
evalmerge(s);
cout
机房租用,北京机房托管,大带宽租用,IDC机房服务器主机租用托管-价格及服务咨询 www.e1idc.net