题解 | #【模板】栈#

【模板】栈

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;
}

全部评论

相关推荐

01-21 12:26
暨南大学 golang
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客企业服务