Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. int input[1001], output[1000], stack[1000], top = -1;
  6.  
  7. static inline void StackPush(int data, int n){
  8. if(++top >= n) return;
  9. stack[top] = data;
  10. }
  11.  
  12. static inline void StackPop(){
  13. if(top <= -1) return;
  14. top--;
  15. }
  16.  
  17. static inline int StackEmpty(){
  18. return top <= -1 ? 1 : 0;
  19. }
  20.  
  21. int main(){
  22.  
  23. while(1){
  24. int n;
  25. scanf("%d", &n);
  26. if(n == 0) break;
  27. while(1){
  28. for(int i = 0; i < n; i++){
  29. scanf("%d", output + i);
  30. if(output[0] == 0) break;
  31. input[i] = i + 1;
  32. }
  33. if(output[0] == 0) {
  34. puts("");
  35. memset(input, 0, sizeof(int) * n);
  36. break;
  37. }
  38. int i = 0, j = 0;//i for input, j for output
  39. while(j < n){
  40.  
  41. if(input[i] == output[j]){
  42. i++;
  43. j++;
  44. }
  45. else if(!StackEmpty() && stack[top] == output[j]){
  46. StackPop();
  47. j++;
  48. }
  49. else if(i < n){
  50. StackPush(input[i], n);
  51. i++;
  52. }
  53. else break;
  54. }
  55. j < n - 1 ? puts("No") : puts("Yes");
  56. top = -1;
  57. }
  58. }
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement