std::vector<int> nums(N);
for (int i = 0; i < N; ++i) {
std::cin >> nums[i];
}
std::stack<int> numStack;
std::stack<char> opStack;
for (int i = 0; i < N - 1; ++i) {
char op;
std::cin >> op;
// 将数字压入数字堆栈
numStack.push(nums[i]);
// 如果运算符堆栈不为空且当前运算符优先级小于等于栈顶运算符优先级,则进行计算
while (!opStack.empty() && (opStack.top() == '*' || opStack.top() == '/') &&
(op == '+' || op == '-')) {
int num2 = numStack.top();
numStack.pop();
int num1 = numStack.top();
numStack.pop();
char operatorChar = opStack.top();
opStack.pop();
// 执行计算
int result;
if (operatorChar == '+') {
result = num1 + num2;
} else if (operatorChar == '-') {
result = num1 - num2;
} else if (operatorChar == '*') {
result = num1 * num2;
} else if (operatorChar == '/') {
if (num2 == 0) {
std::cout << "ERROR: " << num1 << "/0" << std::endl;
return 0;
}
result = num1 / num2;
}
// 将计算结果压回数字堆栈
numStack.push(result);
}
// 将运算符压入运算符堆栈
opStack.push(op);
}
// 将最后一个数字压入数字堆栈
numStack.push(nums[N - 1]);
// 执行剩余的计算
while (!opStack.empty()) {
int num2 = numStack.top();
numStack.pop();
int num1 = numStack.top();
numStack.pop();
char operatorChar = opStack.top();
opStack.pop();
// 执行计算
int result;
if (operatorChar == '+') {
result = num1 + num2;
} else if (operatorChar == '-') {
result = num1 - num2;
} else if (operatorChar == '*') {
result = num1 * num2;
} else if (operatorChar == '/') {
if (num2 == 0) {
std::cout << "ERROR: " << num1 << "/0" << std::endl;
return 0;
}
result = num1 / num2;
}
// 将计算结果压回数字堆栈
numStack.push(result);
}
// 输出最终结果
std::cout << numStack.top() << std::endl;
for (int i = 0; i < N; ++i) {
std::cin >> nums[i];
}
std::stack<int> numStack;
std::stack<char> opStack;
for (int i = 0; i < N - 1; ++i) {
char op;
std::cin >> op;
// 将数字压入数字堆栈
numStack.push(nums[i]);
// 如果运算符堆栈不为空且当前运算符优先级小于等于栈顶运算符优先级,则进行计算
while (!opStack.empty() && (opStack.top() == '*' || opStack.top() == '/') &&
(op == '+' || op == '-')) {
int num2 = numStack.top();
numStack.pop();
int num1 = numStack.top();
numStack.pop();
char operatorChar = opStack.top();
opStack.pop();
// 执行计算
int result;
if (operatorChar == '+') {
result = num1 + num2;
} else if (operatorChar == '-') {
result = num1 - num2;
} else if (operatorChar == '*') {
result = num1 * num2;
} else if (operatorChar == '/') {
if (num2 == 0) {
std::cout << "ERROR: " << num1 << "/0" << std::endl;
return 0;
}
result = num1 / num2;
}
// 将计算结果压回数字堆栈
numStack.push(result);
}
// 将运算符压入运算符堆栈
opStack.push(op);
}
// 将最后一个数字压入数字堆栈
numStack.push(nums[N - 1]);
// 执行剩余的计算
while (!opStack.empty()) {
int num2 = numStack.top();
numStack.pop();
int num1 = numStack.top();
numStack.pop();
char operatorChar = opStack.top();
opStack.pop();
// 执行计算
int result;
if (operatorChar == '+') {
result = num1 + num2;
} else if (operatorChar == '-') {
result = num1 - num2;
} else if (operatorChar == '*') {
result = num1 * num2;
} else if (operatorChar == '/') {
if (num2 == 0) {
std::cout << "ERROR: " << num1 << "/0" << std::endl;
return 0;
}
result = num1 / num2;
}
// 将计算结果压回数字堆栈
numStack.push(result);
}
// 输出最终结果
std::cout << numStack.top() << std::endl;