题解 | #【模板】栈#
【模板】栈
https://www.nowcoder.com/practice/104ce248c2f04cfb986b92d0548cccbf
#include<stdio.h>
#include<string.h>
int arr[100000];
int main()
{
int n,num,count=0;
char temp[100];
scanf("%d",&n);
for(int index=0;index<n;index++)
{
scanf("%s",temp);
if(strcmp(temp,"push")==0) scanf("%d",&arr[count++]);
else if(strcmp(temp,"pop")==0&&count-1>=0)
printf("%d\n",arr[--count]);
else if(strcmp(temp,"top")==0&&count-1>=0)
printf("%d\n",arr[count-1]);
else printf("error\n");
}
puts("\n");
return 0;
}

