fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stack>
  4. using namespace std;
  5.  
  6. int main() {
  7. string s;
  8. stack<int> hi;
  9. while(cin>> s) {
  10. if(s=="push"){
  11. int n;
  12. cin>> n;
  13. hi.push(n);
  14. cout<< "ok" << endl;
  15. }
  16. if(s == "pop"){
  17. cout<<hi.top()<< endl;
  18. hi.pop();
  19. }
  20. if(s == "back"){
  21. cout<<hi.top()<< endl;
  22. }
  23. if(s == "size"){
  24. cout<< hi.size()<< endl;
  25. }
  26. if(s == "clear"){
  27. while(!hi.empty()) {
  28. hi.pop();
  29. cout<< "ok"<< endl;
  30. }
  31. }
  32. if(s == "exit"){
  33. cout << "bye" << endl;
  34. }
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 15240KB
stdin
push 1
back
exit
stdout
ok
1
bye