STL 40pts 求调

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

ice_fish01 @ 2023-03-03 23:26:45

我的代码:请求神犇支援qaq

#include<bits/stdc++.h>
using namespace std;
int a[100010],b[100000],n,q;
signed main()
{
    stack <int> s;
    cin >> q;
    while(q--)
    {
        cin >> n;
        for(int i = 1;i <= n;i++)
            cin >> a[i];
        for(int i = 1;i <= n;i++)
            cin >> b[i];
        int j = 1;
        for(int i = 1;i <= n;i++)
        {
            s.push(a[i]);
            if((s.top()) == b[j])
            {
                s.pop(); 
                j++;
                if(s.empty())
                    break;
            }
        }
        if(s.empty())
            puts("Yes");
        else
            puts("No");
        while(!s.empty())
            s.pop();
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
    }
    return 0;
}

by TheSky233 @ 2023-03-03 23:28:37

@ice_fish01

if((s.top()) == b[j]) \to while((s.top()) == b[j])


by ice_fish01 @ 2023-03-03 23:31:56

@TheSky233

\large \texttt { 哦哦哦哦哦(恍然大悟)}

by ice_fish01 @ 2023-03-03 23:33:24

\large\texttt {感谢 daolao 555}

|