zoukankan      html  css  js  c++  java
  • hoj 2578 Super_Stack 模拟栈

    /*
    
    用结构体数组模拟栈,结构体中保存当前min与max的值
    
    */
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    
    using namespace std;
    
    const int X = 65537;
    
    int n,top;
    
    struct node
    {
        int max,min;
    }stack[X];
    
    int main()
    {
        freopen("sum.in","r",stdin);
        char s[10];
        int x;
        int ncase = 0;
        while(cin>>n,n)
        {
            printf("Case %d\n",++ncase);
            top = 0;
            for(int i=0;i<n;i++)
            {
                scanf("%s",s);
                if(s[0]=='m')
                {
                    if(!top)
                        printf("null\n");
                    else
                    {
                        if(s[1]=='a')
                            printf("%d\n",stack[top-1].max);
                        else
                            printf("%d\n",stack[top-1].min);
                    }
                }
                else
                {
                    if(s[1]=='o')
                    {
                        if(top)
                            top--;
                    }
                    else
                    {
                        scanf("%d",&x);
                        if(top)
                        {
                            stack[top].max = max(x,stack[top-1].max);
                            stack[top].min = min(x,stack[top-1].min);
                        }
                        else
                            stack[top].min = stack[top].max = x;
                        top++;
                    }
                }
            }
        }
    
        return 0;
    }
  • 相关阅读:
    第六周总结
    石家庄地铁线路查询系统
    第五周总结报告
    二维数组
    第四周总结
    个人作业一(补充)
    第三周总结
    个人作业一
    开课博客
    CentOS7 网卡配置文件解释
  • 原文地址:https://www.cnblogs.com/yejinru/p/2608072.html
Copyright © 2011-2022 走看看