#include <stdio.h>
#define SIZE 5
int stack[SIZE];
int sp;
void push(int value);
int pop(void);
int main(void)
{
sp=0;
int resp, data;
while(1){
printf("1:push 2:pop 0:end : ");
if(!resp) break;
switch(resp){
push(data);
break;
case 2: pop();
break;
}
}
for(int i=0; i<sp; i++){
printf("stack[%d]=%d \n", i
, stack
[i
]); }
return 0;
}
void push(int value)
{
if(sp >= SIZE){
}else{
stack[sp++] = value;
}
}
int pop(void)
{
if(sp<= 0){
return 0;
}else{
return stack[--sp];
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIFNJWkUgNQppbnQgc3RhY2tbU0laRV07CmludCBzcDsKCnZvaWQgcHVzaChpbnQgdmFsdWUpOwppbnQgcG9wKHZvaWQpOwoKaW50IG1haW4odm9pZCkgCnsKICAgc3A9MDsKICAgaW50IHJlc3AsIGRhdGE7CiAgIAogICB3aGlsZSgxKXsKICAgCXByaW50ZigiMTpwdXNoIDI6cG9wIDA6ZW5kIDogIik7CiAgIAlzY2FuZigiJWQiLCAmcmVzcCk7CiAgIAkKICAgCWlmKCFyZXNwKSBicmVhazsKICAgCQogICAJc3dpdGNoKHJlc3ApewogICAJCWNhc2UgMTogcHJpbnRmKCJwdXNoIDogIik7IHNjYW5mKCIlZCIsICZkYXRhKTsKICAgCQkgICAgICAgIHB1c2goZGF0YSk7CiAgIAkJICAgICAgICBicmVhazsKICAgCSAgICBjYXNlIDI6IHBvcCgpOwogICAJICAgICAgICAgICAgYnJlYWs7CiAgIAl9CiAgIAlwcmludGYoInNwPSVkXG4iLHNwKTsKICAgfQogICBwcmludGYoIlxuIik7CiAgIGZvcihpbnQgaT0wOyBpPHNwOyBpKyspewogICAJICAgIHByaW50Zigic3RhY2tbJWRdPSVkIFxuIiwgaSwgc3RhY2tbaV0pOwogICB9CiAgIAogICByZXR1cm4gMDsKfQoKdm9pZCBwdXNoKGludCB2YWx1ZSkKewoJIGlmKHNwICA+PSAgU0laRSl7CgkgCSAgIHByaW50Zigi44K544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