题目只是提示四则运算,是否存在负数,是否存在括号等情况并没详细说明,因此为保证程序的健壮性,编写代码时将这两种情况考虑进去,具体的详细注释在代码中体现。
补充测试样例:
13
(-1)*(-1)-1
(-1)*(-1)-(1)*(-1)
(-1*-3*(1*4))*1
(((1+9)))
-1+((-2*-3)*-1)
1+1
2.2/3
1+2*3
1+2*-300
-1+2+0
(-1*(-3+-4-(-1*-2)))
(-2)
2*(-300)/(-2)*2
#include<iostream>
#include<stack>
#include<algorithm>
#include<cstdlib>
#include<cmath>
using namespace std;
int a[300][300]={0};//用来判断该当前字符串是进行入栈操作,还是先出栈再入栈
int book[300]={0};//用来判断'-'是减号还是负号
void init(){
//当前符号是左括号直接入栈
a['('][