#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){
printf("スタックが空で取り出せませんでした\n"); return 0;
}else{
return stack[--sp];
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIFNJWkUgNQppbnQgc3RhY2tbU0laRV07CmludCBzcDsKCnZvaWQgcHVzaChpbnQgdmFsdWUpOwppbnQgcG9wKHZvaWQpOwoKaW50IG1haW4odm9pZCkKewogICBzcD0wOwogICBpbnQgcmVzcCwgZGF0YTsKCiAgIHdoaWxlKDEpewogICAgICAgcHJpbnRmKCIxOnB1c2ggMjpwb3AgMDplbmQgOiAiKTsKICAgICAgIHNjYW5mKCIlZCIsJnJlc3ApOwoKICAgICAgIGlmKCFyZXNwKSBicmVhazsKCiAgICAgICBzd2l0Y2gocmVzcCl7CiAgICAgICAgICAgY2FzZSAxOiBwcmludGYoIjE6cHVzaCA6ICIpOyBzY2FuZigiJWQiLCZkYXRhKTsKICAgICAgICAgICAgICAgICAgIHB1c2goZGF0YSk7CiAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICBjYXNlIDI6IHBvcCgpOwogICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIHByaW50Zigic3A9JWRcbiIsc3ApOwogICAgIH0KICAgICBwcmludGYoIlxuIik7CiAgICAgZm9yKGludCBpPTA7IGk8c3A7IGkrKyl7CiAgICAgICAgIHByaW50Zigic3RhY2tbJWRdPSVkIFxuIiwgaSwgc3RhY2tbaV0pOwogICAgIH0KICAgICAKICAgICByZXR1cm4gMDsKfQp2b2lkIHB1c2goaW50IHZhbHVlKQp7CiAgICBpZihzcCA+PSBTSVpFKXsKICAgICAgICBwcmludGYoIuOCueOCv+ODg+OCr+OBjOa6gOadr+OBp+WFpeOCiuOBvuOBm+OCk+OBp+OBl+OBn1xuIik7CiAgICB9ZWxzZXsKICAgICAgICAgc3RhY2tbc3ArK10gPSB2YWx1ZTsKICAgIH0KfQoKaW50IHBvcCh2b2lkKQp7CiAgICBpZihzcCA8PSAwKXsKICAgICAgICBwcmludGYoIuOCueOCv+ODg+OCr+OBjOepuuOBp+WPluOCiuWHuuOBm+OBvuOBm+OCk+OBp+OBl+OBn1xuIik7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9ZWxzZXsKICAgICAgICByZXR1cm4gc3RhY2tbLS1zcF07CiAgICB9Cn0=