Skip to content

Commit

Permalink
Create 02-线性结构4 Pop Sequence (25 分).cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
hao14293 authored May 1, 2019
1 parent f359021 commit e341136
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ZJU_MOOC_数据结构/02-线性结构4 Pop Sequence (25 分).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include <stack>
#include <vector>
using namespace std;

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

0 comments on commit e341136

Please sign in to comment.