题解 | #堆栈的使用#

堆栈的使用

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

#include <stdio.h>

int main() {
    int n,i;
    while (scanf("%d", &n) != EOF) { // 注意 while 处理多个 case
    	int shuzu[1000];
    	static int end=0;
		for(i=0;i<n;i++){
    		char S;
			scanf("%c",&S);
			if(S=='A'){
				if(end>0){
					printf("%d\n",shuzu[end-1]);
				}else{
					printf("E\n");
				}
			}else if(S=='P'){
				scanf("%d",&shuzu[end]);
				end+=1;
			}else if(S=='O'){
				if(end>0){
					end-=1;
				}
			}
		}
    }
    return 0;
}

全部评论

相关推荐

04-01 11:08
中原工学院 Java
老六f:感觉这种培训期过了就找理由给你开了
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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