Facebook
From Ân, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 141
  1. #include<iostream>
  2. #include<stack>
  3. #include<vector>
  4. #include<algorithm>
  5. #include<sstream>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.    
  12.     vector<string>v;
  13.     stack<string>st;
  14.     int q;
  15.     cin>>q;
  16.        
  17.     while(q--)
  18.     {
  19.        
  20.        
  21.     string s;
  22.     getline(cin,s);
  23.     stringstream ss(s);
  24.     string token;
  25.     while(ss>>token)
  26.     {
  27.         v.push_back(token);
  28.        
  29.         string thaotac=v[0];
  30.         string n=v[1];
  31.         cout<<thaotac<<" ";
  32.         cout<<n<<" ";
  33.            
  34.            
  35.            
  36.             if(thaotac=="push")
  37.         {
  38.             st.push(n);
  39.         }
  40.         if(thaotac=="pop")
  41.         {
  42.             st.pop();
  43.         }
  44.         if(thaotac=="show")
  45.         {
  46.             if(st.empty())
  47.     {
  48.      cout<<"empty"<<" ";
  49.     }
  50.             while (!st.empty())
  51.    {
  52.       v.push_back(st.top());
  53.     st.pop();
  54.      }
  55.     reverse(v.begin(),v.end());
  56.     for(auto it:v)
  57.     {
  58.         cout<<it<<" ";
  59.     }
  60.     }
  61.     }
  62.     }
  63.    
  64.    
  65.        
  66.        
  67.    
  68.     return 0;
  69. }