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