社区讨论
听取WA声一片
P4387【深基15.习9】验证栈序列参与者 4已保存回复 7
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 7 条
- 当前快照
- 1 份
- 快照标识符
- @m65wz35t
- 此快照首次捕获于
- 2025/01/21 11:26 去年
- 此快照最后确认于
- 2025/11/04 11:09 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
void judge(stack<int> pushedt,stack<int> poped){
while(!pushedt.empty( )&&!poped.empty( )){
if(pushedt.top( )!=poped.top( )){
cout<<"No"<<endl;
return;
}
pushedt.pop( );
poped.pop( );
}
cout<<"Yes"<<endl;
}
int main( ){
int Q;cin>>Q;
while(Q--){
stack<int> pushed;
stack<int> poped;
stack<int> pushedt;
int n;cin>>n;
for(int i=0;i<n;i++){
int j;cin>>j;
pushed.push(j);
}
for(int i=0;i<n;i++){
int j;cin>>j;
poped.push(j);
}
//输入
while(!pushed.empty( )){
pushedt.push(pushed.top( ));
pushed.pop( );
}
//把pushed转换成倒序的
judge(pushedt,poped);
//判断是yes还是No
}
return 0;
}
回复
共 7 条回复,欢迎继续交流。
正在加载回复...