Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <stdio.h>
- //#include <stdlib.h>
- //
- //#define MAX 10
- //
- //int count = 0;
- //
- //struct stack {
- // int items[MAX];
- // int top;
- //};
- //typedef struct stack st;
- //
- //void createEmptyStack(st *s) {
- // s->top = -1;
- //}
- //
- //int isfull(st *s) {
- // if (s->top == MAX - 1)
- // return 1;
- // else
- // return 0;
- //}
- //
- //int isempty(st *s) {
- // if (s->top == -1)
- // return 1;
- // else
- // return 0;
- //}
- //
- //void push(st *s, int newitem) {
- // if (isfull(s)) {
- // printf("STACK FULL");
- // } else {
- // s->top++;
- // s->items[s->top] = newitem;
- // }
- // count++;
- //}
- //
- //void pop(st *s) {
- // if (isempty(s)) {
- // printf("\n STACK EMPTY \n");
- // } else {
- // s->top--;
- // }
- // count--;
- // printf("\n");
- //}
- //
- //void printStack(st *s) {
- // printf("Stack: ");
- // for (int i = 0; i < count; i++) {
- // printf("%d ", s->items[i]);
- // }
- // printf("\n");
- //}
- //
- //// Driver code
- //int main() {
- // int ch;
- // st *stack = (st *) malloc(sizeof(st));
- // int q;
- // scanf("%d", &q);
- // int MN = 10000;
- // int SZ = 0;
- // while (q--) {
- // int type;
- // scanf("%d", &type);
- // if (type == 1) {
- // int num;
- // scanf("%d", &num);
- // SZ++;
- // push(stack, num);
- // }
- // if (type == 2) {
- // pop(stack);
- // SZ--;
- // }
- // if (type == 3) {
- // if (SZ > 0) {
- // for (int i = 0; i < SZ; i++) {
- // if (MN > stack->items[i])
- // MN = stack->items[i];
- // }
- // printf("%d\n", MN);
- // } else {
- // printf("\n");
- // }
- // }
- // }
- //}
- #include <bits/stdc++.h>
- using namespace std;
- int main () {
- int q;
- cin >> q;
- stack<int> st;
- stack<int> temp;
- int MN = 1000;
- while (q--) {
- int type;
- cin >> type;
- if (type == 1) {
- int x;
- cin >> x;
- st.push(x);
- }
- if (type == 2) {
- st.pop();
- }
- if (type == 3) {
- temp = st;
- while(not temp.empty()) {
- int cur = temp.top();
- if (cur < MN)
- MN = cur;
- temp.pop();
- }
- cout << MN << '\n';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement