#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];
}
}
I2luY2x1ZGU8c3RkaW8uaD4KCiNkZWZpbmUgU0laRSA1CmludCBzdGFja1tTSVpFXTsKaW50IHNwOwoKdm9pZCBwdXNoKGludCB2YWx1ZSk7CmludCBwb3Aodm9pZCk7CgppbnQgbWFpbih2b2lkKXsKCXNwPTA7CglpbnQgcmVzcCwgZGF0YTsKCgl3aGlsZSgxKXsKCQlwcmludGYoIjE6cHVzaAkyOnBvcAkwOmVuZCA6Iik7CgkJc2NhbmYoIiVkIiwmcmVzcCk7CgoJCWlmKCFyZXNwKSBicmVhazsKCgkJc3dpdGNoKHJlc3ApewoJCQljYXNlIDE6cHJpbnRmKCJwdXNoOgkiKTsgc2NhbmYoIiVkIiwmZGF0YSk7CgkJCQkJCXB1c2goZGF0YSk7CgkJCQkJCWJyZWFrOwoJCQljYXNlIDI6cG9wKCk7CgkJCQkJCWJyZWFrOwoJCX0KCQlwcmludGYoInNwPSVkXG4iLHNwKTsKCX0KCXByaW50ZigiXG4iKTsKCWZvcihpbnQgaT0wOyBpPHNwOyBpKyspewoJCXByaW50Zigic3RhY2tbJWRdPSVkXG4iLGksIHN0YWNrW2ldKTsKCX0KCXJldHVybiAwOwp9Cgp2b2lkIHB1c2goaW50IHZhbHVlKXsKCWlmKHNwID49IFNJWkUpewoJCXByaW50Zigi44K544K/44OD44Kv44GM5rqA5p2v44Gn5YWl44KK44G+44Gb44KT44Gn44GX44GfXG4iKTsKCX0KCWVsc2V7CgkJc3RhY2tbc3ArK109dmFsdWU7Cgl9Cn0KCmludCBwb3Aodm9pZCl7CglpZihzcCA8PSAwKXsKCQkJcHJpbnRmKCLjgrnjgr/jg4Pjgq/jgYznqbrjgaflj5bjgorlh7rjgZvjgb7jgZvjgpPjgafjgZfjgZ9cbiIpOwoJCQlyZXR1cm4gMDsKCQl9CgllbHNlewoJCXJldHVybiBzdGFja1stLXNwXTsKCX0KfQ==