题解 | #【模板】栈#

【模板】栈

https://www.nowcoder.com/practice/104ce248c2f04cfb986b92d0548cccbf

#include <stdio.h>
#include <malloc.h>
#include <string.h>
int main() {
int operation;
scanf("%d",&operation);
int array[100000];
int point = -1;
for(int i = 0;i<operation;i++){
 char* str = (char*)malloc(sizeof(char)*6);
 scanf("%s",str);
    if(!strcmp(str, "push")){
      int tmp ;
      scanf("%d",&tmp);
      point++;
      array[point]=tmp;
    }
    if(!strcmp(str,"pop")){
        if(point<0){
            printf("error\n");
        }else{
              printf("%d\n",array[point]);
        point--;
        }
      
    }
    if(!strcmp(str,"top")){
        if(point<0){
            printf("error\n");
        }else{
            printf("%d\n",array[point]);
        }
        
    }
}
return 0;
}

全部评论

相关推荐

Lorn的意义:1.你这根本就不会写简历呀,了解太少了 2.你这些项目经历感觉真的没啥亮点啊,描述的不行,重写书写一下让人看到核心,就继续海投 注意七八月份ofer还是比较多的,越往后机会越少,抓住时机,抓紧检查疏漏,加油查看图片
点赞 评论 收藏
分享
07-23 15:05
门头沟学院 Java
熊大不大:不好意思KPI数据刚刚刷新,刚刚达标
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务