#include<stdio.h>
#define SIZE 5
int stack[SIZE];
int sp;
void push(int value);
int pop(void);
void display(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: printf( "pop : %d ", 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];
}
}
void display(void){
for(int i=0;i<sp;i++){
printf("stack[%d]=%d\n",i
,stack
[i
]); }
}
I2luY2x1ZGU8c3RkaW8uaD4KCiNkZWZpbmUgU0laRSA1CmludCBzdGFja1tTSVpFXTsKaW50IHNwOwoKdm9pZCBwdXNoKGludCB2YWx1ZSk7CmludCBwb3Aodm9pZCk7CnZvaWQgZGlzcGxheSh2b2lkKTsKCmludCBtYWluKHZvaWQpCnsKICAgIHNwID0gMDsKICAgIGludCByZXNwLCBkYXRhOwoKICAgIHdoaWxlKDEpewogICAgICAgIHByaW50ZigiMe+8mnB1c2jjgIAyOnBvcOOAgDA6ZW5kIDogIik7CiAgICAgICAgc2NhbmYoIiVkIiwgJnJlc3ApOwoKICAgICAgICBpZighcmVzcCkgIGJyZWFrOwoKICAgICAgICBzd2l0Y2gocmVzcCl7CiAgICAgICAgICAgIGNhc2UgMTogcHJpbnRmKCJwdXNoIDogIik7IHNjYW5mKCIlZCIsICZkYXRhKTsKICAgICAgICAgICAgICAgICAgICBwdXNoKCBkYXRhICk7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGNhc2UgMjogcHJpbnRmKCAicG9wIDogJWQgIiwgcG9wKCkgKTsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgcHJpbnRmKCJzcD0lZFxuIiwgc3ApOwogICAgfQogICAgcHJpbnRmKCJcbiIpOwogICAgZm9yKGludCBpPTA7IGk8c3A7IGkrKyl7CiAgICAgICAgcHJpbnRmKCJzdGFja1slZF09JWQgXG4iLCBpLCBzdGFja1tpXSk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0KCnZvaWQgcHVzaChpbnQgdmFsdWUpCnsKICAgIGlmKHNwID49IFNJWkUpewogICAgICAgIHByaW50Zigi44K544K/44OD44Kv44GM5rqA5p2v44Gn5YWl44KK44G+44Gb44KT44Gn44GX44GfXG4iKTsKICAgIH1lbHNlewogICAgICAgIHN0YWNrW3NwKytdID0gdmFsdWU7CiAgICB9Cn0KCmludCBwb3Aodm9pZCkKewogICAgaWYoc3AgPD0gMCl7CiAgICAgICAgcHJpbnRmKCLjgrnjgr/jg4Pjgq/jgYznqbrjgaflj5bjgorlh7rjgZvjgb7jgZvjgpPjgafjgZfjgZ9cbiIpOwogICAgICAgIHJldHVybiAwOwogICAgfWVsc2V7CiAgICAgICAgcmV0dXJuIHN0YWNrWy0tc3BdOwogICAgfQp9Cgp2b2lkIGRpc3BsYXkodm9pZCl7Cglmb3IoaW50IGk9MDtpPHNwO2krKyl7CgkJcHJpbnRmKCJzdGFja1slZF09JWRcbiIsaSxzdGFja1tpXSk7Cgl9Cn0K