Advertisement
Hamoudi30

Untitled

Nov 7th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. //#include <stdio.h>
  2. //#include <stdlib.h>
  3. //
  4. //#define MAX 10
  5. //
  6. //int count = 0;
  7. //
  8. //struct stack {
  9. // int items[MAX];
  10. // int top;
  11. //};
  12. //typedef struct stack st;
  13. //
  14. //void createEmptyStack(st *s) {
  15. // s->top = -1;
  16. //}
  17. //
  18. //int isfull(st *s) {
  19. // if (s->top == MAX - 1)
  20. // return 1;
  21. // else
  22. // return 0;
  23. //}
  24. //
  25. //int isempty(st *s) {
  26. // if (s->top == -1)
  27. // return 1;
  28. // else
  29. // return 0;
  30. //}
  31. //
  32. //void push(st *s, int newitem) {
  33. // if (isfull(s)) {
  34. // printf("STACK FULL");
  35. // } else {
  36. // s->top++;
  37. // s->items[s->top] = newitem;
  38. // }
  39. // count++;
  40. //}
  41. //
  42. //void pop(st *s) {
  43. // if (isempty(s)) {
  44. // printf("\n STACK EMPTY \n");
  45. // } else {
  46. // s->top--;
  47. // }
  48. // count--;
  49. // printf("\n");
  50. //}
  51. //
  52. //void printStack(st *s) {
  53. // printf("Stack: ");
  54. // for (int i = 0; i < count; i++) {
  55. // printf("%d ", s->items[i]);
  56. // }
  57. // printf("\n");
  58. //}
  59. //
  60. //// Driver code
  61. //int main() {
  62. // int ch;
  63. // st *stack = (st *) malloc(sizeof(st));
  64. // int q;
  65. // scanf("%d", &q);
  66. // int MN = 10000;
  67. // int SZ = 0;
  68. // while (q--) {
  69. // int type;
  70. // scanf("%d", &type);
  71. // if (type == 1) {
  72. // int num;
  73. // scanf("%d", &num);
  74. // SZ++;
  75. // push(stack, num);
  76. // }
  77. // if (type == 2) {
  78. // pop(stack);
  79. // SZ--;
  80. // }
  81. // if (type == 3) {
  82. // if (SZ > 0) {
  83. // for (int i = 0; i < SZ; i++) {
  84. // if (MN > stack->items[i])
  85. // MN = stack->items[i];
  86. // }
  87. // printf("%d\n", MN);
  88. // } else {
  89. // printf("\n");
  90. // }
  91. // }
  92. // }
  93. //}
  94.  
  95. #include <bits/stdc++.h>
  96. using namespace std;
  97. int main () {
  98. int q;
  99. cin >> q;
  100. stack<int> st;
  101. stack<int> temp;
  102. int MN = 1000;
  103. while (q--) {
  104. int type;
  105. cin >> type;
  106. if (type == 1) {
  107. int x;
  108. cin >> x;
  109. st.push(x);
  110. }
  111. if (type == 2) {
  112. st.pop();
  113. }
  114. if (type == 3) {
  115. temp = st;
  116. while(not temp.empty()) {
  117. int cur = temp.top();
  118. if (cur < MN)
  119. MN = cur;
  120. temp.pop();
  121. }
  122. cout << MN << '\n';
  123. }
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement