fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. ll n;
  6. stack<ll> st;
  7.  
  8. int main(){
  9. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  10. cin >> n;
  11. for(int i=1; i<=n; i++){
  12. ll j; cin >> j;
  13. if(j == 1){
  14. ll a; cin >> a;
  15. st.push(a);
  16. }
  17. else if(j == 2) st.pop();
  18. else{
  19. if(st.empty()) cout << "Empty!" << '\n';
  20. else cout << st.top() << '\n';
  21. }
  22. }
  23. }
Success #stdin #stdout 0.01s 5504KB
stdin
6
1 15
1 20
2
3
2
3
stdout
15
Empty!