stack80分,求助

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

jikky @ 2024-07-04 16:27:11

#include<bits/stdc++.h>
using namespace std;
int a[100002];
int c[100002];
stack<int> line;
int q;
int n;
int t=0;
int main(){

    cin>>q;
    while(q){
        cin>>n;
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        for(int i=0;i<n;i++){
            scanf("%d",&c[i]);
        }
        for(int i=0;i<n;i++){
            line.push(a[i]);
            while(line.top()==c[t]){
                line.pop();
                t++;
                if(line.empty()){
                    break;
                }
            }
        }
        if(t==n){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
        t=0;
        q--;
        for(int i=0;i<n;i++){
            a[i]=0;
            c[i]=0;
        }
    }
    return 0;
}

by steelhzg @ 2024-07-05 23:33:14

你的栈清空了么


by jikky @ 2024-07-10 08:58:20

@steelhzg 谢谢大佬


|