求调%%%
查看原帖
求调%%%
1297464
ljlthu楼主2025/1/26 22:44
//2025.1.26 ljl luogu P4387 【深基15.习9】验证栈序列
#include <bits/stdc++.h>
using namespace std;
int t, a;
int c[100005], d[100005];
stack<int>s;

int main() {
	cin >> t;
	while (t--) {
		cin >> a;
		for (int i = 1; i <= a; i++)
			cin >> c[i], s.push(c[i]);
		for (int i = 1; i <= a; i++)
			cin >> d[i];
		int sum = 1;
		while (!s.empty() && s.top() == d[sum]) {
			s.pop();
			sum++;
		}
		if (s.empty())
			cout << "Yes\n";
		else
			cout << "No\n";
		while (!s.empty())
			s.pop();
		//清空栈,第一次提交没清空WA了
	}
	return 0;
}
2025/1/26 22:44
加载中...