样例过了,但是是零分

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

a2lyaXNhbWUgbWFyaXNh @ 2022-07-12 11:15:15

rt

还请大佬帮忙指出问题所在%%%

//P4387
#include<bits/stdc++.h>
using namespace std;
int main() {
    int q,n;
    bool f=1;
    stack<int>p;
    cin>>q;
    while(q--) {
        cin>>n;
        int a[n],b[n];
        for(int i=0; i<n; i++)
            cin>>a[i];
        for(int i=0; i<n; i++)
            cin>>b[i];
        for(int i=0; i<n; i++)
            p.push(a[i]);
        for(int i=0;i<n;i++){
            if(p.top()!=b[i]){
                f=0;
                break;
            }
            p.pop();
        }
        if(f)cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}

悬赏关注


by Hisaishi_Kanade @ 2022-07-12 11:17:05

@S__B 不一定要全部进栈才一个个出栈


by a2lyaXNhbWUgbWFyaXNh @ 2022-07-12 11:17:53

@bye_wjx 进站后马上出站??


by Hisaishi_Kanade @ 2022-07-12 11:21:03

@S__B 不一定,这才是这题的精髓


by iqer @ 2022-07-12 11:22:05

而且f没有刷新


by a2lyaXNhbWUgbWFyaXNh @ 2022-07-12 11:23:28

@iqer 原来如此,谢谢啦,过了给关注


by a2lyaXNhbWUgbWFyaXNh @ 2022-07-12 12:35:02

@iqer 还是不行,样例和自测数据都过了LG就是不过……


by space_sea @ 2022-10-15 08:36:38

谁能帮忙看看我代码吗...


|