0分求调,玄关

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

Foraver @ 2024-03-02 14:47:16

#include<bits/stdc++.h>
using namespace std;
stack <int> q;
int n,t,cnt=1;
int main()
{
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        int a[10005],b[10005];
        scanf("%d",&n);
        for(int j=1;j<=n;j++)scanf("%d",&a[j]);
        for(int j=1;j<=n;j++)scanf("%d",&b[j]);
        for(int j=1;j<=n;j++)
        {
            q.push(a[j]);
            if(q.top()==b[cnt])
            {
                while(!q.empty()&&q.top()!=b[cnt])
                {
                    q.pop();
                    cnt++;
                }
            }
        }
        for(int j=1;j<=n&&!q.empty();j++)if(q.top()==b[cnt])q.pop(),cnt++;
        if(q.empty())printf("Yes\n");
        else printf("No\n");
        while(!q.empty())q.pop();
        cnt=1;
    }
    return 0;
}

不是我看完所有帖子,规避了所有错误,但是0分


by 2022cxy @ 2024-03-02 15:31:14

@Foraver 你确定10000够了?


by Foraver @ 2024-03-02 15:36:32

@2022cxy 谢谢,但是全WA


by Foraver @ 2024-03-02 15:37:44

我已经改了


by 2022cxy @ 2024-03-02 15:43:58

@Foraver 应该是这里出问题了(勿喷


for(int j=1;j<=n&&!q.empty();j++)if(q.top()==b[cnt])q.pop(),cnt++;

by Foraver @ 2024-03-02 15:48:36

@2022cxy哪错了呀


by Foraver @ 2024-03-02 15:49:29

@2022cxy 哪错了呀


by Foraver @ 2024-03-02 17:05:35

@2022cxy 谢谢谢谢谢谢,已关注并AC


|