zoukankan      html  css  js  c++  java
  • 数据结构实验之栈与队列七:出栈序列判定

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    # define maxn 100000+10
    int t1[maxn],t2[maxn];
    int main()
    {
        ios::sync_with_stdio(false);
        int n;
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&t1[i]);
        }
        int m;
        int temp;
        scanf("%d",&m);
        while(m--)
        {
            int s1=0,s2=0;
            for(int i=1; i<=n; i++)
            {
                int temp;
                scanf("%d",&temp);
                while(s2==0||t2[s2]!=temp)
                {
                    if(s1>n)break;
                    t2[++s2]=t1[++s1];
                }
                if(t2[s2]==temp)
                {
                    s2--;
                }
            }
            if(s2==0)
                printf("yes
    ");
            else
                printf("no
    ");
    
        }
        return 0;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  • 相关阅读:
    jsp实现登陆功能小实验
    netty
    shiro
    mybatis
    spring MVC
    spring
    集合框架面试题
    Redis面试题
    Dubbo面试题汇总
    阿里面试题
  • 原文地址:https://www.cnblogs.com/letlifestop/p/10262921.html
Copyright © 2011-2022 走看看