PAT甲级1051题(堆栈)


1.题目介绍

1051

2.考察点,难度

模拟现实类,模拟堆栈,数据结构,难度易

3.解题代码

#include <cstdio>
#include <stack>
using namespace std;

int main()
{
	int m, n, k;
	scanf("%d %d %d", &m, &n, &k);
	for (int i = 0; i < k; i++){
		int seq[n+1];
		stack<int> pop;
		for (int j = 1; j < n+1; j++) scanf("%d", seq+j);
		int current = 1;
		for (int j = 1; j < n+1; j++){
			pop.push(j);
			if (pop.size() > m) break;
			while (!pop.empty() && pop.top() == seq[current]){
				pop.pop();
				current++;
			}
		}
		if (current < n+1) printf("NO\n");
		else printf("YES\n");
	}
	return 0;
}

文章作者: Peyton
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Peyton !
  目录