fork download
  1. #include <iostream>
  2. #include <stack>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main() {
  7. stack<int>p;
  8. int n;
  9. cin>>n;
  10. while(n--){
  11. string g;
  12. cin>>g;
  13. int o;
  14. if(g=="push"){
  15. cin>>o;
  16. p.push(o);
  17. }else if(g=="top"){
  18. cout<<p.top()<<endl;
  19. }
  20. else if(g=="pop"){
  21.  
  22. p.pop();
  23. }
  24. }}
  25.  
Success #stdin #stdout 0s 5324KB
stdin
10
push 5
top
push 6
top
push 3
top
pop
top
pop
top
stdout
5
6
3
6
5