Facebook
From Nguyen Gia Hy, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 122
  1. #include <iostream>
  2. #include <stack>
  3. #include <vector>]
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.  int q;
  10.  cin>>q;
  11.  vector <int> v;
  12.  stack <int> st;
  13.  while (q--){
  14.   string s;
  15.   getline (cin, s);
  16.   if (s == "push"){
  17.    int n;
  18.    cin>>n;
  19.    st.push(n);
  20.   }
  21.   if (s == "pop"){
  22.    st.pop();
  23.   }
  24.   if (s == "show"){
  25.    while (!st.empty()){
  26.     v.push_back(st.top());
  27.     st.pop();
  28.    }
  29.    reverse(v.begin(), v.end());
  30.    for (auto x : v){
  31.     cout<<x<<" ";
  32.    }
  33.   }
  34.  
  35.  }
  36. }