#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int *stackbase;
int *stack;
int stack_size;
void stackerr(char* str)
{
}
void init_stack(int smax)
{
stackbase
= (int *)malloc(smax
* sizeof(int)); if (stackbase == NULL)
{
stackerr("init error");
}
stack = stackbase;
stack_size = smax;
}
void extend_stack(void)
{
int *p, new;
new = stack_size * 2;
p
= (int *)realloc(stackbase
, new
* sizeof(int)); if (p == NULL)
{
stackerr("extend error");
}
stack = p + (stack - stackbase);
stackbase = p;
stack_size = new;
}
void print_stack(void)
{
int *p = stack;
int n = 0;
while (p > stackbase)
{
p--;
n++;
}
}
void push(int x)
{
if (stack >= stackbase + stack_size)
{
extend_stack();
}
*stack = x;
stack++;
}
int pop(void)
{
if (stack <= stackbase)
{
stackerr("Underflow");
}
stack--;
return *stack;
}
void calc(int *a, int c)
{
int x;
int y;
int i;
int n;
for (i = 0; i < c; i++)
{
n = a[i];
if (n == -10000)
{
y = pop();
x = pop();
push(x + y);
}
else if (n == -10001)
{
y = pop();
x = pop();
push(x * y);
}
else if (n == -10002)
{
break;
}
else
{
push(n);
}
}
}
int main(int argc, char* argv[])
{
int i;
char* arg;
int x;
int y;
init_stack(1);
for (i = 1; i < argc; i++)
{
arg = argv[i];
{
y = pop();
x = pop();
push(x + y);
}
else if (strcmp(arg
, "x") == 0) {
y = pop();
x = pop();
push(x * y);
}
else if (strcmp(arg
, "p") == 0) {
}
else
{
}
}
return EXIT_SUCCESS;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKaW50ICpzdGFja2Jhc2U7CmludCAqc3RhY2s7CmludCBzdGFja19zaXplOwoKdm9pZCBzdGFja2VycihjaGFyKiBzdHIpCnsKICAgIHByaW50ZigiJXNcbiIsIHN0cik7CiAgICBleGl0KDk5OSk7Cn0KCnZvaWQgaW5pdF9zdGFjayhpbnQgc21heCkKewogICAgc3RhY2tiYXNlID0gKGludCAqKW1h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W50ICphLCBpbnQgYykKewogICAgaW50IHg7CiAgICBpbnQgeTsKICAgIGludCBpOwogICAgaW50IG47CiAgICBmb3IgKGkgPSAwOyBpIDwgYzsgaSsrKQogICAgewogICAgICAgIG4gPSBhW2ldOwogICAgICAgIGlmIChuID09IC0xMDAwMCkKICAgICAgICB7CiAgICAgICAgICAgIHkgPSBwb3AoKTsKICAgICAgICAgICAgeCA9IHBvcCgpOwogICAgICAgICAgICBwdXNoKHggKyB5KTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAobiA9PSAtMTAwMDEpCiAgICAgICAgewogICAgICAgICAgICB5ID0gcG9wKCk7CiAgICAgICAgICAgIHggPSBwb3AoKTsKICAgICAgICAgICAgcHVzaCh4ICogeSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKG4gPT0gLTEwMDAyKQogICAgICAgIHsKICAgICAgICAgICAgcHJpbnRmKCIlZFxuIiwgcG9wKCkpOwogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgIHsKICAgICAgICAgICAgcHVzaChuKTsKICAgICAgICB9CiAgICB9Cn0KCmludCBtYWluKGludCBhcmdjLCBjaGFyKiBhcmd2W10pCnsKICAgIGludCBpOwogICAgY2hhciogYXJnOwogICAgaW50IHg7CiAgICBpbnQgeTsKCiAgICBpbml0X3N0YWNrKDEpOwogICAgZm9yIChpID0gMTsgaSA8IGFyZ2M7IGkrKykKICAgIHsKICAgICAgICBhcmcgPSBhcmd2W2ldOwogICAgICAgIGlmIChzdHJjbXAoYXJnLCAiKyIpID09IDApCiAgICAgICAgewogICAgICAgICAgICB5ID0gcG9wKCk7CiAgICAgICAgICAgIHggPSBwb3AoKTsKICAgICAgICAgICAgcHVzaCh4ICsgeSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKHN0cmNtcChhcmcsICJ4IikgPT0gMCkKICAgICAgICB7CiAgICAgICAgICAgIHkgPSBwb3AoKTsKICAgICAgICAgICAgeCA9IHBvcCgpOwogICAgICAgICAgICBwdXNoKHggKiB5KTsKICAgICAgICB9CiAgICAgICAgZWxzZSBpZiAoc3RyY21wKGFyZywgInAiKSA9PSAwKQogICAgICAgIHsKICAgICAgICAgICAgcHJpbnRmKCIlZFxuIiwgcG9wKCkpOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBwdXNoKGF0b2koYXJnKSk7CiAgICAgICAgfQogICAgfQoKICAgIHJldHVybiBFWElUX1NVQ0NFU1M7Cn0K