#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){
case 1:
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+CgojZGVmaW5lIFNJWkUgNQppbnQgc3RhY2tbU0laRV07CmludCBzcDsKCnZvaWQgcHVzaChpbnQgdmFsdWUpOwppbnQgcG9wKHZvaWQpOwoKaW50IG1haW4odm9pZCkgCnsKICAgIHNwID0gMDsKICAgIGludCByZXNwLCBkYXRhOwogICAgCiAgICB3aGlsZSgxKXsKICAgICAgICBwcmludGYoIjE6cHVzaCAyOnBvcCAwOmVuZCA6ICIpOwogICAgICAgIHNjYW5mKCIlZCIsICZyZXNwKTsgCiAgICAgICAgCiAgICAgICAgaWYoIXJlc3ApIGJyZWFrOwogICAgICAgIAogICAgICAgIHN3aXRjaChyZXNwKXsKICAgICAgICAgICAgIGNhc2UgMTogCiAgICAgICAgICAgICAgICBwcmludGYoInB1c2ggOiAiKTsgCiAgICAgICAgICAgICAgICBzY2FuZigiJWQiLCAmZGF0YSk7IAogICAgICAgICAgICAgICAgcHVzaChkYXRhKTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBjYXNlIDI6IAogICAgICAgICAgICAgICAgcG9wKCk7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgcHJpbnRmKCJzcD0lZFxuIiwgc3ApOwogICAgfQkKICAgIAogICAgcHJpbnRmKCJcbiIpOwogICAgZm9yKGludCBpPTA7IGk8c3A7IGkrKyl7CiAgICAgICAgcHJpbnRmKCJzdGFja1slZF09JWRcbiIsIGksIHN0YWNrW2ldKTsKICAgIH0KICAgIAogICAgcmV0dXJuIDA7Cn0KCnZvaWQgcHVzaChpbnQgdmFsdWUpCnsKICAgIGlmKHNwID49IFNJWkUpeyAgCiAgICAgICAgcHJpbnRmKCLjgrnjgr/jg4Pjgq/jgYzmuoDmna/jgaflhaXjgorjgb7jgZvjgpPjgafjgZfjgZ9cbiIpOwogICAgfSBlbHNlIHsKICAgICAgICBzdGFja1tzcCsrXSA9IHZhbHVlOyAKICAgIH0KfQoKaW50IHBvcCh2b2lkKQp7CiAgICBpZihzcCA8PSAwKXsgCiAgICAgICAgcHJpbnRmKCLjgrnjgr/jg4Pjgq/jgYznqbrjgaflj5bjgorlh7rjgZvjgb7jgZvjgpPjgafjgZfjgZ9cbiIpOwogICAgICAgIHJldHVybiAwOyAgCiAgICB9IGVsc2UgewogICAgICAgIHJldHVybiBzdGFja1stLXNwXTsgCiAgICB9Cn0=