#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;
char str[10];
int cnt[256] = {};
// process
int main()
{
FILE *fp;
int i;
fp
= fopen("c161-102.c.in", "r"); while ((fscanf(fp
, "%s", str
)) != EOF
) res();
printf("\nresult = %d\n", pop
()); for ( i = 0; i < 256; ++i)
if (cnt[i])
return 0;
}
void res()
{
int a, b;
char c;
c = str[0];
switch (c) {
case '+':
cnt[c]++;
a = pop();
b = pop();
push(b + a);
break;
case '-':
cnt[c]++;
a = pop();
b = pop();
push(b - a);
break;
case '*':
cnt[c]++;
a = pop();
b = pop();
push(b * a);
break;
case '/':
cnt[c]++;
a = pop();
b = pop();
if (a == 0)
break;
push(b / a);
break;
default:
break;
}
}
void push(int w)
{
st[pt++] = w;
}
int pop()
{
return st[--pt];
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2RlZmluZSBTVEFDS19NQVggKDEwMCkKCi8vIHByb3RvdHlwZQp2b2lkIHJlcygpOwp2b2lkIHB1c2goaW50IHcpOwppbnQgcG9wKCk7CgovLyBnbG9iYWwKaW50IHN0W1NUQUNLX01BWF07CmludCBwdCA9IDA7CmNoYXIgc3RyWzEwXTsKaW50IGNudFsyNTZdID0ge307CgovLyBwcm9jZXNzCmludCBtYWluKCkKewogIEZJTEUgKmZwOwogIGludCBpOwoKICBmcCA9IGZvcGVuKCJjMTYxLTEwMi5jLmluIiwgInIiKTsKICBwcmludGYoImlucHV0ID0gIik7CiAgd2hpbGUgKChmc2NhbmYoZnAsICIlcyIsIHN0cikpICE9IEVPRikKICAgIHJlcygpOwogIHByaW50ZigiXG5yZXN1bHQgPSAlZFxuIiwgcG9wKCkpOwogIGZvciAoIGkgPSAwOyBpIDwgMjU2OyArK2kpCiAgICBpZiAoY250W2ldKQogICAgICBwcmludGYoIiVjICVkXG4iLCBpLCBjbnRbaV0pOwoKICByZXR1cm4gMDsKfQoKCnZvaWQgcmVzKCkKewogIGludCBhLCBiOwogIGNoYXIgYzsKCiAgcHJpbnRmKCIlcyAiLCBzdHIpOwogIGMgPSBzdHJbMF07CgogIHN3aXRjaCAoYykgewogIGNhc2UgJysnOgogICAgY250W2NdKys7CiAgICBhID0gcG9wKCk7CiAgICBiID0gcG9wKCk7CiAgICBwdXNoKGIgKyBhKTsKICAgIGJyZWFrOwogIGNhc2UgJy0nOgogICAgY250W2NdKys7CiAgICBhID0gcG9wKCk7CiAgICBiID0gcG9wKCk7CiAgICBwdXNoKGIgLSBhKTsKICAgIGJyZWFrOwogIGNhc2UgJyonOgogICAgY250W2NdKys7CiAgICBhID0gcG9wKCk7CiAgICBiID0gcG9wKCk7CiAgICBwdXNoKGIgKiBhKTsKICAgIGJyZWFrOwogIGNhc2UgJy8nOgogICAgY250W2NdKys7CiAgICBhID0gcG9wKCk7CiAgICBiID0gcG9wKCk7CiAgICBpZiAoYSA9PSAwKQogICAgICBicmVhazsKICAgIHB1c2goYiAvIGEpOwogICAgYnJlYWs7CiAgZGVmYXVsdDoKICAgIHB1c2goYXRvaShzdHIgKSk7CiAgICBicmVhazsKICB9Cn0KCnZvaWQgcHVzaChpbnQgdykKewogIHN0W3B0KytdID0gdzsKfQoKaW50IHBvcCgpCnsKICByZXR1cm4gc3RbLS1wdF07Cn0K