Skip to content

Instantly share code, notes, and snippets.

@nyufeng
Created April 2, 2019 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nyufeng/1bc66b614807d31054e7d27a524b13de to your computer and use it in GitHub Desktop.
Save nyufeng/1bc66b614807d31054e7d27a524b13de to your computer and use it in GitHub Desktop.
Pop Sequence
#include "stdio.h"
#include "stdlib.h"
int main(){
int MAX, length, row;
scanf("%d %d %d", &MAX, &length, &row);
int max[row][length];
for(int i = 0; i < row; i++){
for(int k = 0; k < length; k++){
scanf("%d", &max[i][k]);
}
}
int stack[MAX], current, q, isTrue;
for(int i = 0; i < row; i++){
current = -1, q = 0, isTrue = 1;
for(int k = 0; k < length; k++){
while(current == -1 || max[i][k] != stack[current]){
if(current >= MAX - 1){
isTrue = 0;
break;
}
if(q >= length){
isTrue = 0;
break;
}
stack[++current] = ++q;
}
if(isTrue == 0){
break;
}
current--;
}
if(isTrue == 1){
printf("YES\n");
}else{
printf("NO\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment