验证栈序列
#include<bits/stdc++.h>
using namespace std;
int main() {
int q; cin >> q;
for (int i = 0; i < q; i++) {
int n, x; cin >> n;
stack<int> pushed;
vector<int> a, b;
for (int j = 0; j < n; j++) {
cin >> x;
a.push_back(x);
}
for (int j = 0; j < n; j++) {
cin >> x;
b.push_back(x);
}
int count = 0;
for (int j = 0; j < n; j++) {
pushed.push(a[j]);
while (pushed.top() == b[count]) {
pushed.pop(); count++;
if (pushed.empty()) break;
}
}
if (pushed.empty()) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
标签:count,int,++,cin,pushed,push,模拟
From: https://www.cnblogs.com/rjxq/p/18206633