RE但是过了样例
查看原帖
RE但是过了样例
1046320
panbojun楼主2024/8/3 16:47
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int q;
stack<int> st;
void clean(){
	while(st.size() > 0){
		st.pop();
	}
	return ;
}
int main(){
	cin >> q;
	while(q --){
		clean();//每次清空栈 
		int n, pu[N], pop[N], f = 0;
		cin >> n;
		for(int i = 1; i <= n; i++) cin >> pu[i];
		for(int i = 1; i <= n; i++) cin >> pop[i];
		int step = 1;//记录当前出栈的 
		for(int i = 1; i <= n; i++){
			st.push(pu[i]);//当前数入栈 
			while(st.top() == pop[step]){//如果与出栈序列相同 
				st.pop(); //出栈 
				step ++; //把此时应出栈的数换下一个 
				if(step >= n + 1){
					cout << "Yes" << '\n';
					f ++; break;
				}
			}
		}
		if(f == 0) cout << "No" << '\n';
	}
	return 0;
}
2024/8/3 16:47
加载中...