daily pastebin goal
58%
SHARE
TWEET

Untitled

Godrambo Apr 17th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top