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

Posted cnxz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了山理工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 ");
else {j-=1;}
}
else if(strcmp(str,str3)==0)
{
if(j<0) printf("empty ");
else printf("%d ",a[j]);
}
}
printf(" ");
}
}

以上是关于山理工oj 2556传说中的数据结构的主要内容,如果未能解决你的问题,请参考以下文章