数据结构实验之栈与队列七:出栈序列判定

代码:

#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;
}

















原文地址:https://www.cnblogs.com/letlifestop/p/10262921.html