论为什么过了样例还是爆零(求助)
查看原帖
论为什么过了样例还是爆零(求助)
137627
wweiyuzhao楼主2021/8/29 09:07
#include<iostream>
#include<stack>
using namespace std;
stack<int>q;
int n,m,pu[100005],po[100005];
int s; 
bool flag()
{
	for(int i=1;i<=m;i++)
	{
		if(!q.empty()&&q.top()==po[i])
		{
			q.pop();
			continue;
		}
		while(s<=m&&pu[s]!=po[i])
		{
			q.push(pu[s]);
			s++;
		}
		if(s>m)
		{
			return 0;
		}
		s++;
	}
	return 1;
}
int main()
{
	cin>>n;
	while(n--)
	{
		cin>>m;
		for(int i=1;i<=m;i++)
		{
			cin>>pu[i];
		}
		for(int i=1;i<=m;i++)
		{
			cin>>po[i];
		}
		while(!q.empty())
		{
			q.pop();
		}
		if(flag())
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	return 0;
}
2021/8/29 09:07
加载中...