Facebook
From Ân, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 138
  1. #include<iostream>
  2. #include<stack>
  3. #include<vector>
  4. using namespace std;
  5. int main()
  6. {
  7.     vector<int>v;
  8.     stack<int>st;
  9.     int q;
  10.     cin>>q;
  11.        
  12.     while(q--)
  13.     {
  14.        
  15.         string thaotac;
  16.         getline(cin,thaotac);
  17.    
  18.        
  19.         if(thaotac=="push")
  20.         {
  21.             int n;
  22.             cin>>n;
  23.             st.push(n);
  24.         }
  25.         if(thaotac=="pop")
  26.         {
  27.             st.pop();
  28.         }
  29.         if(thaotac=="show")
  30.         {
  31.             if(st.empty())
  32.     {
  33.      cout<<"empty";
  34.     }
  35.             while (!st.empty())
  36.    {
  37.       v.push_back(st.top());
  38.     st.pop();
  39.      }
  40.     reverse(v.begin(),v.end());
  41.     for(auto it:v)
  42.     {
  43.         cout<<it<<" ";
  44.     }
  45.     }
  46.     }
  47.    
  48.     return 0;
  49. }