#include<stdio.h>
#include<string.h>
#include<stack>
#include<iostream>
using namespace std;
int main()
{
int T;
while(scanf("%d",&T)!=EOF)
{
getchar();
stack<int>q;
while(T--)
{
char s[20];
scanf("%s",s);
if(strcmp(s,"push")==0)
{
int e;
scanf("%d",&e);
q.push(e);
}
if(strcmp(s,"pop")==0)
{
if(q.empty())
printf("this is empty!\n");
else
{
cout << q.top() << endl;
q.pop();
}
}
if(strcmp(s,"query")==0)
{
if(q.empty())
printf("this is empty!\n");
else
{
while(!q.empty())
{
cout << q.top() << endl;
q.pop();
}
}
}
}
printf("\n");
}
}
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#define maxsize 100
typedef struct stack
{
int data[maxsize];
int top;
} Stack;
Stack *q;
void Initstack(Stack *q)
{
q->top=-1;
}
void pushstack(Stack *q,int e)
{
q->top++;
q->data[q->top]=e;
}
void popstack(Stack *q)
{
if(q->top==-1)
printf("this is empty!\n");
else
{
int e=q->data[q->top];
printf("%d\n",e);
q->top--;
}
}
void query(Stack *q)
{
if(q->top==-1)
printf("this is empty!\n");
else
{
while(q->top>=0)
{
printf("%d\n",q->data[q->top]);
q->top--;
}
}
}
int main()
{
int T;
while(scanf("%d",&T)!=EOF)
{
getchar();
q=(Stack *)malloc(sizeof(Stack));
Initstack(q);
while(T--)
{
char s[20];
scanf("%s",s);
if(strcmp(s,"push")==0)
{
int e;
scanf("%d",&e);
pushstack(q,e);
}
if(strcmp(s,"pop")==0)
{
popstack(q);
}
if(strcmp(s,"query")==0)
{
query(q);
}
}
free(q);
printf("\n");
}
}