fork(3) download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <stack>
  4. using namespace std;
  5.  
  6.  
  7. stack<int> s;
  8. char str[100];
  9. int n;
  10. int main(void)
  11. {
  12. while(scanf("%s",&str))
  13. {
  14. if (strcmp(str,"push") == 0)
  15. {
  16. cin>>n;;
  17. s.push(n);
  18. cout<<"ok"<<"\n";
  19. } else
  20. if (strcmp(str,"pop") == 0)
  21. {
  22. cout<<s.top()<<"\n";
  23. s.pop();
  24. } else
  25. if (strcmp(str,"back") == 0)
  26. {
  27. cout<<s.top()<<"\n";;
  28. } else
  29. if (strcmp(str,"size") == 0)
  30. {
  31. cout<<s.size()<<"\n";
  32. } else
  33. if (strcmp(str,"clear") == 0)
  34. {
  35. while(!s.empty())
  36. s.pop();
  37. cout<<"ok"<<"\n";
  38. } else
  39. {
  40. cout<<"bye"<<"\n";
  41. break;
  42. }
  43. }
  44. return 0;
  45. }
Success #stdin #stdout 0s 4496KB
stdin
push 2
push 3
push 5
back
size
pop
size 
push 7 
pop 
clear 
size 
exit
stdout
ok
ok
ok
5
3
5
2
ok
7
ok
0
bye