/**用一个栈,数字就入,运算符就取两个计算
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param tokens string字符串一维数组
* @param tokensLen int tokens数组长度
* @return int整型
*/
#include <stdio.h>
#include <string.h>
int evalRPN(char** tokens, int tokensLen ) {
int stack[10000];
int point = 0;
for (int i = 0; i < tokensLen; i++) {
if (!strcmp(tokens[i], "+")) {
stack[point - 2] = stack[point - 2] + stack[point - 1];
point = point - 1;
} else if (!strcmp(tokens[i], "-")) {
stack[point - 2] = stack[point - 2] - stack[point - 1];
point = point - 1;
} else if (!strcmp(tokens[i], "*")) {
stack[point - 2] = stack[point - 2] * stack[point - 1];
point = point - 1;
} else if (!strcmp(tokens[i], "/")) {
stack[point - 2] = stack[point - 2] / stack[point - 1];
point = point - 1;
} else {
stack[point] = atoi(tokens[i]);
point++;
}
}
return stack[0];
}