#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 : \n");
		scanf("%d",&resp);
		
		if(!resp){
			break;
		}
		switch(resp){
			case 1:
			     scanf("%d",&data);
			     push(data);
			     break;
			case 2:
			     printf("pop : %d\n",pop());
			     break;
		}
		printf("sp=%d",sp);
	}
	printf("\n");
	for(int i = 0;i < sp;i ++){
		printf("stack[%d]=%d",i,stack[i]);
	}
	return 0;
}

void push(int value){
	if(sp >= SIZE){
		printf("スタックが満杯で入りませんでした。\n");
	}else{
		stack[sp++] = value;
	}
}

int pop(void){
	if(sp <= 0){
		printf("スタックが空で取り出せませんでした。\n");
		return 0;
	}else{
		return stack[--sp];
	}
}
