Luochen567 @ 2023-11-08 13:06:08
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int n, m;
int z[100005] = { 0 }; //模拟入栈
int sx[100005] = { 0 };//模拟顺序
bool mz(int m)
{
int sxi = 1, zi = 1;
while (sxi <= m) //遍历出栈顺序
{
while (z[zi] != sx[sxi]&&zi<=m)//找到相同的数
{
zi++;
}
if (zi > m)//如果在栈数组中从当前位置及后面找不到数据,就返回false
{
return false;
}
else
{
zi--;
}//找到了数据后zi--模拟前一个数据的出栈,zi指向栈的下一个
sxi++;//找出栈顺序的下一个
}
return true;
}
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> m;
for (int i = 1; i <= m; i++)
{
cin >> z[i];
}
for (int i = 1; i <= m; i++)
{
cin >> sx[i];
}
if (mz(m))
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
}
return 0;
}
by bohemiao @ 2023-11-29 12:53:33
没有指针