题解 | 堆栈的使用(14行够了)

堆栈的使用

https://www.nowcoder.com/practice/e91982a145944ceab6bb9a4a508e0e26

#include <stdio.h>

int main() {
    int stk[1000], top, n;
    while (top=-1, scanf("%d", &n) != EOF) {
        char c;
        for(int i=0; i<n&&scanf(" %c", &c); ++i){
            if(c=='A' && top==-1) printf("E\n");
            else if(c=='A') printf("%d\n", stk[top]);
            else if(c=='P') scanf("%d", &stk[++top]);
            else if(top>-1) --top;
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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