![]() |
#2
流照君2019-07-16 16:20
|
给一个序列进栈,求给出的序列是否可以出栈得到

#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack>
using namespace std;
const int inf=1005;
int main()
{
int n,m,t,a[inf];
stack<int> s;
cin>>n>>m>>t;
while(t--)
{
for(int i=0;i<m;i++)
cin>>a[i];
int i=1,j=0;
while(j<m&&i<=m)
{
s.push(i);
i++;
while(s.top()==a[j]&&s.size()>0&&j<m&&i<=m)
{
j++;
s.pop();
}
}
if(s.empty()!=true)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
while(s.empty()!=true)
s.pop();
}
return 0;
}
#include<cstring>
#include<algorithm>
#include<stack>
using namespace std;
const int inf=1005;
int main()
{
int n,m,t,a[inf];
stack<int> s;
cin>>n>>m>>t;
while(t--)
{
for(int i=0;i<m;i++)
cin>>a[i];
int i=1,j=0;
while(j<m&&i<=m)
{
s.push(i);
i++;
while(s.top()==a[j]&&s.size()>0&&j<m&&i<=m)
{
j++;
s.pop();
}
}
if(s.empty()!=true)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
while(s.empty()!=true)
s.pop();
}
return 0;
}
就是这段出错 段错误
while(s.top()==a[j]&&s.size()>0&&j<m&&i<=m)
{
j++;
s.pop();
}
[此贴子已经被作者于2019-7-16 16:21编辑过]