ALDS1_3_A 2018-2-21

#include
#include
#include
using namespace std;

int CharToInt(char s[]) {
    int ans = 0, i = 0;
    while (s[i] != '\0') {
        ans = ans * 10 + s[i] - '0';
        i++;
    }
    return ans;
}

int main() {
    char s[1000];
    int a, b;
    stack S;

    while(scanf("%s",s)!=EOF){
            if (s[0] == '+') {
                b = S.top(); S.pop();
                a = S.top(); S.pop();
                S.push(a + b);
            }else if (s[0] == '-') {
                b = S.top(); S.pop();
                a = S.top(); S.pop();
                S.push(a - b);
            }else if (s[0] == '*') {
                b = S.top(); S.pop();
                a = S.top(); S.pop();
                S.push(a * b);
            }else {
                S.push(CharToInt(s));
            }
    }
    printf("%d\n", S.top());

    return 0;
}

你可能感兴趣的:(ACM动态规划)