Gooooogle • 5个月前
#include <iostream>
#include <stack>
using namespace std;
int main() {
int q, n, a[10001], b[10001], flag = 1;
stack<int>val;
cin >> q;
for (int i = 0; i < q; i++) {
int j, k, t = 0;
cin >> n;
//输入序列
for (j = 0; j < n; j++) {
cin >> a[j];
}
for (j = 0; j < n; j++) {
cin >> b[j];
}
//进出栈
for (k = 0; k < n; k++) {
val.push(a[k]);
while (!val.empty()&& val.top() == b[t] ) {
//cout << val.top() << " ";
val.pop();
t++;
}
//cout << "123" << endl;
}
if (!val.empty())
printf("No\n");
else
printf("Yes\n");
while (!val.empty()) val.pop();
}
return 0;
}
评论:
请先登录,才能进行评论