Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<stdio.h>
- #include<string.h>
- int input[1001], output[1000], stack[1000], top = -1;
- static inline void StackPush(int data, int n){
- if(++top >= n) return;
- stack[top] = data;
- }
- static inline void StackPop(){
- if(top <= -1) return;
- top--;
- }
- static inline int StackEmpty(){
- return top <= -1 ? 1 : 0;
- }
- int main(){
- while(1){
- int n;
- scanf("%d", &n);
- if(n == 0) break;
- while(1){
- for(int i = 0; i < n; i++){
- scanf("%d", output + i);
- if(output[0] == 0) break;
- input[i] = i + 1;
- }
- if(output[0] == 0) {
- puts("");
- memset(input, 0, sizeof(int) * n);
- break;
- }
- int i = 0, j = 0;//i for input, j for output
- while(j < n){
- if(input[i] == output[j]){
- i++;
- j++;
- }
- else if(!StackEmpty() && stack[top] == output[j]){
- StackPop();
- j++;
- }
- else if(i < n){
- StackPush(input[i], n);
- i++;
- }
- else break;
- }
- j < n - 1 ? puts("No") : puts("Yes");
- top = -1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement