为什么过不了啊啊啊啊啊啊啊啊啊啊啊?!?!?求助
查看原帖
为什么过不了啊啊啊啊啊啊啊啊啊啊啊?!?!?求助
251775
galiyuebing楼主2021/8/13 14:49
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <stack>
using namespace std;
stack<int>  a;
int n,q,j,k;
int b,in[100002],out[100002];
int main()
{
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		cin>>n;
		for(j=1;j<=n;j++)
		{
			cin>>in[j];		//输入 
		}
		for(j=1;j<=n;j++)
		{
			cin>>out[j];	//输入 
		}
		for(j=1,k=1;j<=n;j++)
		{
			a.push(in[j]);	//读入栈 
			while(true)
			{
				if((a.top())==out[k])
				{
					k++;
					a.pop();
				}
				else
					break;
				if(a.empty())
				{
					cout<<"Yes"<<endl;
					break;
				}
			}
		}
		if(!a.empty())
		{
			cout<<"No"<<endl;
		}
	}
	return 0;
}


2021/8/13 14:49
加载中...