#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main() {
char* src = "1 2 + 4 5 + * 3 /";
int ns[256];
int ni;
char cs[16];
int ci;
int i;
char c;
int l;
int n1;
int n2;
ni = 0;
ci = 0;
for (i = 0; i < l; i++) {
c = src[i];
if (c == ' ') {
if (ci > 0) {
cs[ci] = '\0';
ci = 0;
}
cs[ci++] = c;
} else if (c == '+') {
n2 = ns[--ni];
n1 = ns[--ni];
ns[ni++] = n1 + n2;
} else if (c == '-') {
n2 = ns[--ni];
n1 = ns[--ni];
ns[ni++] = n1 - n2;
} else if (c == '*') {
n2 = ns[--ni];
n1 = ns[--ni];
ns[ni++] = n1 * n2;
} else if (c == '/') {
n2 = ns[--ni];
n1 = ns[--ni];
ns[ni++] = n1 / n2;
}
}
printf("expression %s\n", src
); if (ni > 0) {
printf("result %d\n", ns
[--ni
]); } else {
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8Y3R5cGUuaD4KCmludCBtYWluKCkgewogIGNoYXIqIHNyYyA9ICIxIDIgKyA0IDUgKyAqIDMgLyI7CgogIGludCBuc1syNTZdOwogIGludCBuaTsKCiAgY2hhciBjc1sxNl07CiAgaW50IGNpOwoKICBpbnQgaTsKICBjaGFyIGM7CiAgaW50IGw7CiAgCiAgaW50IG4xOwogIGludCBuMjsKCiAgbmkgPSAwOwogIGNpID0gMDsKICBsID0gc3RybGVuKHNyYyk7CiAgZm9yIChpID0gMDsgaSA8IGw7IGkrKykgewogICAgYyA9IHNyY1tpXTsKICAgIGlmIChjID09ICcgJykgewogICAgICBpZiAoY2kgPiAwKSB7CiAgICAgICAgY3NbY2ldID0gJ1wwJzsKICAgICAgICBuc1tuaSsrXSA9IGF0b2koY3MpOwogICAgICAgIGNpID0gMDsKICAgICAgfQogICAgfSBlbHNlIGlmIChpc2RpZ2l0KGMpKSB7CiAgICAgIGNzW2NpKytdID0gYzsKICAgIH0gZWxzZSBpZiAoYyA9PSAnKycpIHsKICAgICAgbjIgPSBuc1stLW5pXTsKICAgICAgbjEgPSBuc1stLW5pXTsKICAgICAgbnNbbmkrK10gPSBuMSArIG4yOwogICAgfSBlbHNlIGlmIChjID09ICctJykgewogICAgICBuMiA9IG5zWy0tbmldOwogICAgICBuMSA9IG5zWy0tbmldOwogICAgICBuc1tuaSsrXSA9IG4xIC0gbjI7CiAgICB9IGVsc2UgaWYgKGMgPT0gJyonKSB7CiAgICAgIG4yID0gbnNbLS1uaV07CiAgICAgIG4xID0gbnNbLS1uaV07CiAgICAgIG5zW25pKytdID0gbjEgKiBuMjsKICAgIH0gZWxzZSBpZiAoYyA9PSAnLycpIHsKICAgICAgbjIgPSBuc1stLW5pXTsKICAgICAgbjEgPSBuc1stLW5pXTsKICAgICAgbnNbbmkrK10gPSBuMSAvIG4yOwogICAgfQogIH0KICAKICBwcmludGYoImV4cHJlc3Npb24gJXNcbiIsIHNyYyk7CiAgaWYgKG5pID4gMCkgewogICAgcHJpbnRmKCJyZXN1bHQgJWRcbiIsIG5zWy0tbmldKTsKICB9IGVsc2UgewogICAgcHJpbnRmKCJyZXN1bHQgJXNcbiIsIHNyYyk7CiAgfQogIAogIHJldHVybiAwOwp9