题目概述:
# 【深基15.习9】验证栈序列
## 题目描述
给出两个序列 pushed 和 poped 两个序列,其取值从 1 到 $n(n\le100000)$。已知入栈序列是 pushed,如果出栈序列有可能是 poped,则输出 `Yes`,否则输出 `No`。为了防止骗分,每个测试点有多组数据。
## 输入格式
第一行一个整数 $q$,询问次数。
接下来 $q$ 个询问,对于每个询问:
第一行一个整数 $n$ 表示序列长度;
第二行 $n$ 个整数表示入栈序列;
第三行 $n$ 个整数表示出栈序列;
## 输出格式
对于每个询问输出答案。
## 样例 #1
### 样例输入 #1
```
2
5
1 2 3 4 5
5 4 3 2 1
4
1 2 3 4
2 4 1 3
```
### 样例输出 #1
```
Yes
No
```
本题需要注意检查栈空。
完整代码如下:
#include<bits/stdc++.h>
using namesp[N];
void checace std;
const int N=1e5+2;
int a[N],bk(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++){
scanf("%d",&b[i]);
}
stack<int>st;
int i=1,j=1;
for(int i=1;i<=n;i++){
st.push(a[i]);
while(!st.empty() && st.top()==b[j]){
st.pop();
j++;
}
}
if(st.empty()) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
int main(){
int q;
scanf("%d",&q);
for(int i=1;i<=q;i++){
check();
}
return 0;
}