求助,样例过了但是全WA

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

沉默cxy @ 2023-08-09 11:42:19

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int q,i,j,n,a[100002]={0},b[100002]={0},m,c[100002],t=0;
    scanf("%d",&q);
    for(i=1;i<=q;i++)
    {
        for(j=1;j<=n;j++)
        {
            a[j]=0;b[j]=0;
        }
        scanf("%d",&n);
        for(j=1;j<=n;j++)
            scanf("%d",&a[j]);
        for(j=1;j<=n;j++)
            scanf("%d",&b[j]);
        m=n;
        for(j=1;j<=n;j++)
        {
            if(b[j]==a[m])
            {

                m--;

            }
            else
            {
                if(b[i]!=a[m]&&b[i]!=0)
                {
                    t=1;break;
                }
                if(b[i]==0)
                {
                    m=0;break;
                }
            }

        }
    if(m==0&&t==0)
    printf("Yes\n");
    else
    printf("No\n");
    }

    return 0;

}

by Patrick_Liu_Bingxian @ 2023-08-09 12:00:25

#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<bitset>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;

int main(){
    int t;
    cin>>t;
    for(int k=1;k<=t;k++){
        queue<int>q;
        stack<int>s;
        int n,a[100001],x;
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        for(int i=1;i<=n;i++){
            cin>>x;
            q.push(x);
        }
        for(int i=1;i<=n;i++){
            s.push(a[i]);
            while(s.size()>0&&s.top()==q.front()){
                s.pop();
                q.pop();
            }
        }
        if(s.size()==0)
          cout<<"Yes\n";
        else
          cout<<"No\n";
    }
    return 0;
}

写了一下

我的代码,求关


by bubu12 @ 2023-08-19 16:37:14

@Patrick_Liu_Bingxian 关


|