山理工oj 2556传说中的数据结构

#include<stdio.h>
#include<string.h>
int main()
{
int n,i,j=0,k,a[1000];
char str1[5]="push",str2[4]="pop",str3[4]="top",str[8];
while(~scanf("%d",&n))
{
j=-1;
memset(a,0,sizeof(a));
for(i=0;i<=n-1;i++)
{
scanf("%s",str);
if(strcmp(str,str1)==0)
{
scanf("%d",&k);
a[++j]=k;
}
else if(strcmp(str,str2)==0)
{
if(j<0) printf("error\n");
else {j-=1;}
}
else if(strcmp(str,str3)==0)
{
if(j<0) printf("empty\n");
else printf("%d\n",a[j]);
}
}
printf("\n");
}
}

猜你喜欢

转载自www.cnblogs.com/Cnxz/p/11668026.html