fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. std::ios::sync_with_stdio(false);
  6. cin.tie(0);
  7. int key,t,n;
  8. stack<int>p;
  9. cin>>t;
  10. while (t-->0)
  11. {
  12. cin>>key;
  13. if (key==1)
  14. {
  15. cin>>n;
  16. p.push(n);
  17. }
  18. else
  19. if (key==2)
  20. {
  21. if (!p.empty())p.pop();
  22. }
  23. else
  24. if (key==3)
  25. {
  26. if (!p.empty()) cout<<p.top()<<endl;
  27. else cout<<"Empty!"<<endl;
  28. }
  29. }
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 4500KB
stdin
Standard input is empty
stdout
Standard output is empty