#include <iostream>
using namespace std;
struct stack
{
int top;
int *s;
};
void Push(stack &x, int i)
{
x.s[++x.top]= i;
}
void Pop(stack &x)
{
int res = x.s[x.top--];
//cout << res<<" ";
}
int main()
{
stack x;
int n, k, m;
cin >> m >> k >> n;
x.top = -1;//初始化
x.s = new int[k];//初始化
int *temp = new int[k];
int i;
while (n--)
{
for (i = 0; i < k; i++)
cin >> temp[i];
i = 0;
int j = 1;
x.top = -1;//相当于清空栈
while (i < k&&x.top<m)
{
if (x.s[x.top] == temp[i])
{
Pop(x);
i++;
}
else
{
Push(x, j);
j++;
}
}
if (i < k)//比较未完成,即因为存储超过最大栈空间而结束
cout << "NO"<<endl;
else//待比较数组中所有元素都已完成
cout << "YES" << endl;
}
system("pause");
return 0;
}
PAT A1051 Pop Sequence(自己实现栈)
最新推荐文章于 2023-05-15 23:49:34 发布