#include <iostream> #include <stack> using namespace std; int q,n,a[100000],b[100000],num; int main() { cin>>q; stack<int>s; for(int j=0;j<q;++j){ cin>>n; num=0; for(int i=0;i<n;++i){//输入 cin>>a[i]; } for(int i=0;i<n;++i){ cin>>b[i]; } for(int i=0;i<n;++i){ s.push(a[i]);//进栈 while((s.top())==b[num]){//若匹配符合 s.pop();//出栈 num++; if(s.empty()) break;//若空时结束防止越界 } } if(s.empty()) cout<<"Yes"<<endl;//全部出栈 else{ cout<<"No"<<endl; while(!s.empty()) s.pop();//清空为下一次判断 } } return 0; }
直接模拟栈
标签:验证,int,w5,num,100000,序列,include From: https://www.cnblogs.com/lijunjie03/p/17334738.html