#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+CgojZGVmaW5lIFNJWkUgNQppbnQgc3RhY2tbU0laRV07CmludCBzcDsKCnZvaWQgcHVzaChpbnQgdmFsdWUpOwppbnQgcG9wKHZvaWQpOwoKaW50IG1haW4odm9pZCkKewoJc3A9MDsKCWludCByZXNwLCBkYXRhOwoJCgl3aGlsZSgxKXsKCQlwcmludGYoIjE6cHVzaCAgMjpwb3AgIDA6ZW5kIDogIik7CgkJc2NhbmYoIiVkIiwmcmVzcCk7CgkJCgkJaWYoIXJlc3ApIGJyZWFrOwoJCQoJCXN3aXRjaChyZXNwKXsKCQkJY2FzZSAxOiAJcHJpbnRmKCJwdXNoIDogIik7IHNjYW5mKCIlZCIsJmRhdGEpOwoJCQkgICAgICAgICAgICBwdXNoKGRhdGEpOwoJCQkgICAgICAgICAgICBicmVhazsKCQkJY2FzZSAyOiAgICAgcG9wKCk7CgkJCSAgICAgICAgICAgIGJyZWFrOwoJCX0KCQlwcmludGYoInNwPSVkXG4iLHNwKTsKCX0KCXByaW50ZigiXG4iKTsKCWZvcihpbnQgaT0wOyBpPHNwOyBpKyspewoJCXByaW50Zigic3RhY2tbJWRdPSVkIFxuIiwgaSwgc3RhY2tbaV0pOwoJfQoJCglyZXR1cm4gMDsKfQoKICB2b2lkIHB1c2goaW50IHZhbHVlKQogIHsKICAJICAgaWYoc3A+PVNJWkUpewogIAkgICAJICAgcHJpbnRmKCLjgrn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