社区讨论
论为什么过了样例还是爆零(求助)
P4387【深基15.习9】验证栈序列参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lobvid11
- 此快照首次捕获于
- 2023/10/30 03:37 2 年前
- 此快照最后确认于
- 2023/11/04 08:40 2 年前
CPP
#include<iostream>
#include<stack>
using namespace std;
stack<int>q;
int n,m,pu[100005],po[100005];
int s;
bool flag()
{
for(int i=1;i<=m;i++)
{
if(!q.empty()&&q.top()==po[i])
{
q.pop();
continue;
}
while(s<=m&&pu[s]!=po[i])
{
q.push(pu[s]);
s++;
}
if(s>m)
{
return 0;
}
s++;
}
return 1;
}
int main()
{
cin>>n;
while(n--)
{
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>pu[i];
}
for(int i=1;i<=m;i++)
{
cin>>po[i];
}
while(!q.empty())
{
q.pop();
}
if(flag())
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...