#include <string.h>
#include <stdlib.h>

int evalRPN(char** tokens, int tokensLen) {
    int stack[tokensLen];
    int top = -1;

    for (int i = 0; i < tokensLen; i++) {
        if (strcmp(tokens[i], "+") == 0) {
            int a = stack[top--];
            int b = stack[top--];
            stack[++top] = b + a;
        } else if (strcmp(tokens[i], "-") == 0) {
            int a = stack[top--];
            int b = stack[top--];
            stack[++top] = b - a;
        } else if (strcmp(tokens[i], "*") == 0) {
            int a = stack[top--];
            int b = stack[top--];
            stack[++top] = b * a;
        } else if (strcmp(tokens[i], "/") == 0) {
            int a = stack[top--];
            int b = stack[top--];
            stack[++top] = b / a;
        } else {
            stack[++top] = atoi(tokens[i]); // 将字符串转换为整数再入栈
        }
    }

    return stack[top]; // 返回栈顶元素,即表达式的值
}