Advertisement
Godrambo

Untitled

Apr 17th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include<iostream>
  2. #include<stack>
  3. #include<queue>
  4. #include<string>
  5.  
  6. using namespace std;
  7.  
  8. stack <int> s;
  9. string a;
  10. int x;
  11.  
  12. int main(){
  13.     while(1){
  14.         cin>>a;
  15.         if( a == "push"){
  16.             cin>>x;
  17.             s.push(x);
  18.         }
  19.         else if ( a == "pop"){
  20.             s.pop();
  21.         }
  22.         else if( a == "top"){
  23.             if(!s.empty()) cout<<s.top()<<endl;
  24.             else cout<<"-1";
  25.         }
  26.         else if( a == "size"){
  27.             cout<<s.size()<<endl;
  28.         }
  29.         else if( a == "empty"){
  30.             if(!s.empty()) cout<<"0"<<endl;
  31.             else cout<<"1"<<endl;
  32.         }
  33.         else if( a == "end"){
  34.             break;
  35.         }
  36.         else if( a == "init"){
  37.             for(int i=s.size();i>=0;i--)
  38.                 s.pop();
  39.         }
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement