为什么过不去?
查看原帖
为什么过不去?
526938
_hello_w_楼主2021/12/24 20:17
# include <bits/stdc++.h>
using namespace std;

int q,n,pushed[100005],poped[100005];
stack<int> a;
int main()
{
	cin>>q;
	for (int i = 0; i < q; i++)  
	{
		cin>>n;
		for (int j = 0; j < n; j++) cin>>pushed[j]; 
		for (int j = 0; j < n; j++) cin>>poped[j];  
		int t = 0;
		for (int j = 0; j < n; j++)
		{
			a.push(pushed[j]);
			while (!a.empty() && a.top() == poped[t])  
			{
				a.pop();t++;  
			}
		}
		if (a.empty()) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		while (!a.empty()) a.pop();  
	}
	return 0;
 } 
2021/12/24 20:17
加载中...