fork download
  1. #include <stdio.h>
  2. #include <algorithm>
  3. using namespace std;
  4. int top = 1, top2;
  5. int push(int arr3[], int x, int size)
  6. {
  7. top++;
  8. arr3[top] = x;
  9. }
  10. int pop()
  11. {
  12. top = top - 1;
  13. }
  14. int topi()
  15. {
  16. return top;
  17. }
  18. bool isempty()
  19. {
  20. if (top == -1)
  21. return false;
  22. else
  23. return true;
  24. }
  25. int main()
  26. {
  27. int a, b, c, d, e, f, g, h, i, m, num = 0;
  28. while (1)
  29. {
  30. scanf("%d", &a);
  31. if (a == 0)
  32. break;
  33. else
  34. {
  35. int arr[a + 1], arr2[a + 1], arr3[a + 1];
  36. for (b = 0; b < a; b++)
  37. {
  38. scanf("%d", &arr[b]);
  39. arr2[b] = arr[b];
  40. }
  41. sort(arr, arr + a); //arr sorted arr2 original 1 2 2 1 a=2;
  42. i = 0;
  43. int l = 0;
  44. arr3[topi()] = 0;
  45. for (c = 0; c < a; c++)
  46. {
  47. for (b = l; b < a; b++)
  48. {
  49. if (arr[c] == arr3[topi()])
  50. {
  51. pop();
  52. i++;
  53. b = b - 1;
  54. break;
  55. }
  56. else if (arr[c] != arr2[b])
  57. {
  58. push(arr3, arr2[b], a);
  59. }
  60. else if (arr[c] == arr2[b])
  61. {
  62. i++;
  63. break;
  64. }
  65. }
  66. l = b + 1;
  67. if (l == a)
  68. break;
  69. else
  70. {
  71. m++;
  72. }
  73. }
  74. for (e = 0; e < a; e++)
  75. {
  76. if (arr[e] == arr3[topi()])
  77. {
  78. i++;
  79. pop();
  80. }
  81. }
  82. }
  83. if (i == a)
  84. printf("%d yes\n", num++);
  85. else
  86. printf("%d no\n", num++);
  87. }
  88. }
  89.  
Runtime error #stdin #stdout 0s 3472KB
stdin
5
2 3 1 4 5
5
2 3 1 5 4
5
2 3 4 1 5
5
2 3 4 5 1
5
2 3 5 1 4
5
2 3 5 4 1
5
2 4 1 3 5
5
2 4 1 5 3
5
2 4 3 1 5
5
2 4 3 5 1
5
2 4 5 1 3
5
2 4 5 3 1
5
2 5 1 3 4
5
2 5 1 4 3
5
2 5 3 1 4
5
2 5 3 4 1
5
2 5 4 1 3
5
2 5 4 3 1
5
3 1 2 4 5
5
3 1 2 5 4
5
3 1 4 2 5
5
3 1 4 5 2
5
3 1 5 2 4
5
3 1 5 4 2
5
3 2 1 4 5
5
3 2 1 5 4
5
3 2 4 1 5
5
3 2 4 5 1
5
3 2 5 1 4
5
3 2 5 4 1
0
stdout
Standard output is empty