求助!

P4387 【深基15.习9】验证栈序列

wlmqlzm @ 2022-02-18 10:48:24

#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005],c[100005];
int main()
{
    int n,q,i,j,head,tail;
    cin>>q;
    while(q--)
    {
        cin>>n;
        for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
        for(i=1;i<=n;i++)
        scanf("%d",&c[i]);
        tail=1,head=1;
        for(i=1,j=1;i<=n;i++)
        {
            b[head++]=a[i];
            while(b[head-1]==c[j]&&head>1&&j<=n)
            {
                head--;
                j++;
            }
        }
        if(head==tail) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

样例是对的,但交上去0分


by 编码落寞 @ 2022-02-18 11:02:19

@wlmqlzm

Yes No


by wlmqlzm @ 2022-02-18 11:08:58

@编码落寞 对了,多谢!


|