Advertisement
LEGEND2004

Implement a stack

Feb 10th, 2023
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int t,x,k;
  6.     stack<int> s;
  7.     cin >> t;
  8.     while(t--){
  9.         cin >> k;
  10.         if(k == 1){
  11.             cin >> x;
  12.             s.push(x);
  13.         }else{
  14.             cout << s.top() << endl;
  15.             s.pop();
  16.         }
  17.     }
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement