Evaluate Reverse Polish Notation:题目链接 AC code:123456789101112131415161718192021222324252627282930313233基本思想:因为已经是后缀表达式了,遍历给出的表达式,遇到数字进栈,遇到符号出栈两个数进行运算再存入栈中,最后栈顶元素就是答案*/int (char **tokens, int tokensSize) { int stack[10000]; // 用数组模拟栈 int top = -1; for (int i = 0; i < tokensSize; ++i) { if (isdigit(tokens[i][0]) || (tokens[i][0] == '-' && isdigit(tokens[i][1]))) { //如果是数字 "-11"单独考虑 stack[++top] = atoi(tokens[i]); } else { // 操作符 printf("%sn", tokens[i]); switch (tokens[i][0]) { case '+': stack[top - 1] = stack[top - 1] + stack[top]; top--; break; case '-': stack[top - 1] = stack[top - 1] - stack[top]; top--; break; case '*': stack[top - 1] = stack[top - 1] * stack[top]; top--; break; case '/': stack[top - 1] = stack[top - 1] / stack[top]; top--; break; } } } return stack[top];}