首页 > 其他 > 详细

九度OJ-1108-堆栈的使用

时间:2015-03-25 23:33:39      阅读:410      评论:0      收藏:0      [点我收藏+]
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int n;
char str[10];
int top;
int stack[10010];

int main(){
    freopen("input.txt","r",stdin);

    while(scanf("%d",&n)!=EOF&&n){
        top=-1;
        memset(stack,0,sizeof(stack));
        for (int i = 0; i < n; ++i)
        {
            scanf("%s",str);
            if (str[0]==‘A‘)
            {
                if (top>=0)
                    printf("%d\n",stack[top]);
                else
                    printf("E\n");
            }else if(str[0]==‘P‘){
                int tmp;
                scanf("%d",&tmp);
                stack[++top]=tmp;
            }else
                if (top>=0)
                    top--;          
        }
        printf("\n");
    }
    return 0;
}

九度OJ-1108-堆栈的使用

原文:http://blog.csdn.net/li8630/article/details/44630575

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!