eolymp
bolt
Try our new interface for solving problems
Problems

Implement a stack

published at 1/9/24, 8:22:37 pm
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    stack<int> st;
    int m, n, x;
    cin>>m;
    for(int i = 0; i < m; i++){
        cin>>n;
        if(n == 1){
            cin>>x;
            st.push(x);
        }
        else if (n == 2){
            cout<<st.top()<<endl;
            st.pop();
        }
    }
    return 0;
}