0分求助┭┮﹏┭┮(玄关)
查看原帖
0分求助┭┮﹏┭┮(玄关)
1199534
ycy1124楼主2024/4/17 15:34
#include<bits/stdc++.h>
using namespace std;
queue<int>k1;
stack<int>k;
void read(int &x)
{
	int f=1;
	x=0;
	char ch=getchar();
	while((ch>'9'||ch<'0')&&ch!='-')
	{
		ch=getchar();
	}
	if(ch=='-')
	{
		f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x*=10;
		x+=ch-'0';
		ch=getchar();
	}
	x*=f;
}
int main()
{
	int q;
	read(q);
	while(q)
	{
		bool bj=1;
		q--;
		int n;
		read(n);
		int js=0;
		for(int i=1;i<=n;i++)
		{
			int x;
			read(x);
			k1.push(x);
		}
		for(int i=1;i<=n;i++)
		{
			js++;
			int x;
			read(x);
			if(!k.empty())
			{
				if(k.top()==x)
				{
					cout<<js<<" k "<<k.top()<<'\n';
					k.pop();
				}
			}
			while(!k1.empty()&&x!=k1.front())
			{
				k.push(k1.front());
				k1.pop();
			}
			if(!k1.empty())
			{
				cout<<js<<" k1 "<<k1.front()<<'\n';
				k1.pop();
			}
		}
		while(!k.empty())
		{
			bj=0;
			k.pop();
		}
		if(bj)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	return 0;
}
2024/4/17 15:34
加载中...