一定要注意在判断top或者pop的时候一定要非空。
比如下面这句,while的判断条件前后颠倒就会出现段错误,血泪教训
while(!s.empty()&&s.top()==a[t])
{
s.pop();
t++;
}
#include<iostream>
#include<cstdio>
#include<stack>
#include<algorithm>
using namespace std;
int a[1001];
stack<int>s;
int main()
{
int m,n,k;
cin>>m>>n>>k;
for(int i=0;i<k;i++)
{
int t=1;
while(!s.empty())
{
s.pop();
}
for (int j=1;j<=n;j++)
{
scanf("%d",&a[j]);
}
for(int j=1;j<=n;j++)
{
s.push(j);
if(s.size()>m)
{
break;
}
while(!s.empty()&&s.top()==a[t])
{
s.pop();
t++;
}
}
if(!s.empty())
{
printf("NO\n");
}
else
{
printf("YES\n");
}
}
}