#include <stdio.h>
#include <stdlib.h>
#define STACK_MAX (100)
// prototype
void res();
void push(int w);
int pop();
// global
int st[STACK_MAX];
int pt = 0;
int cnt[256] = {0};
// process
int main()
{
FILE *fp;
int i;
char buffer[1024];
char *str;
fp
= fopen("c161-102.c.in", "r"); while (str
= fgets(buffer
, sizeof(buffer
), fp
)) { res(str);
printf("result = %d\n", pop
()); }
for ( i = 0; i < 256; ++i)
if (cnt[i])
return 0;
}
void res(char *str)
{
int a, b, i;
for (i = 0;str[i] != '\0';i++){
switch (str[i]) {
case '+':
a=pop();
b=pop();
push(b+a);
break;
case '-':
a=pop();
b=pop();
push(b-a);
break;
case '*':
a=pop();
b=pop();
push(b*a);
break;
case '/':
a=pop();
b=pop();
if (a==0)
break;
push(b/a);
break;
case ' ':
case '\n':
break;
default:
push((int)str[i]-'0');
}
}
}
void push(int w)
{
st[pt++] = w;
}
int pop()
{
return st[--pt];
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2RlZmluZSBTVEFDS19NQVggKDEwMCkKIAovLyBwcm90b3R5cGUKdm9pZCByZXMoKTsKdm9pZCBwdXNoKGludCB3KTsKaW50IHBvcCgpOwogCi8vIGdsb2JhbAppbnQgc3RbU1RBQ0tfTUFYXTsKaW50IHB0ID0gMDsKaW50IGNudFsyNTZdID0gezB9OwogCi8vIHByb2Nlc3MKaW50IG1haW4oKQp7CiAgRklMRSAqZnA7CiAgaW50IGk7CiAgY2hhciBidWZmZXJbMTAyNF07CiAgY2hhciAqc3RyOwoKICBmcCA9IGZvcGVuKCJjMTYxLTEwMi5jLmluIiwgInIiKTsKICB3aGlsZSAoc3RyID0gZmdldHMoYnVmZmVyLCBzaXplb2YoYnVmZmVyKSwgZnApKSB7CiAgICBwcmludGYoImlucHV0ICA9ICVzIiwgc3RyKTsKICAgIHJlcyhzdHIpOwoJcHJpbnRmKCJyZXN1bHQgPSAlZFxuIiwgcG9wKCkpOwogIH0KICBmb3IgKCBpID0gMDsgaSA8IDI1NjsgKytpKQogICAgaWYgKGNudFtpXSkKICAgICAgcHJpbnRmKCIlYyAlZFxuIiwgaSwgY250W2ldKTsKIAogIHJldHVybiAwOwp9CiAKIAp2b2lkIHJlcyhjaGFyICpzdHIpCnsKICBpbnQgYSwgYiwgaTsKIAogIGZvciAoaSA9IDA7c3RyW2ldICE9ICdcMCc7aSsrKXsKICAgICAgc3dpdGNoIChzdHJbaV0pIHsKICAgICAgICAgIGNhc2UgJysnOgogICAgICAgICAgICAgIGE9cG9wKCk7CiAgICAgICAgICAgICAgYj1wb3AoKTsKICAgICAgICAgICAgICBwdXNoKGIrYSk7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICctJzoKICAgICAgICAgICAgICBhPXBvcCgpOwogICAgICAgICAgICAgIGI9cG9wKCk7CiAgICAgICAgICAgICAgcHVzaChiLWEpOwogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAnKic6CiAgICAgICAgICAgICAgYT1wb3AoKTsKICAgICAgICAgICAgICBiPXBvcCgpOwogICAgICAgICAgICAgIHB1c2goYiphKTsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgIGNhc2UgJy8nOgogICAgICAgICAgICAgIGE9cG9wKCk7CiAgICAgICAgICAgICAgYj1wb3AoKTsKICAgICAgICAgICAgICBpZiAoYT09MCkKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgcHVzaChiL2EpOwogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAnICc6CiAgICAgICAgICBjYXNlICdcbic6CgkJCSAgYnJlYWs7CiAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIHB1c2goKGludClzdHJbaV0tJzAnKTsKICAgICAgfQogIH0KfQogCnZvaWQgcHVzaChpbnQgdykKewogIHN0W3B0KytdID0gdzsKfQogCmludCBwb3AoKQp7CiAgcmV0dXJuIHN0Wy0tcHRdOwp9CiA=