Advertisement
mickypinata

SMMR-T149: Two Stacks One Queue

Jun 17th, 2021
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.  
  6.     int n;
  7.     scanf("%d", &n);
  8.     stack<int> stk[2];
  9.     for(int i = 1; i <= n; ++i){
  10.         char cmd;
  11.         scanf(" %c%*c%*c", &cmd);
  12.         if(cmd == 'e'){
  13.             int x;
  14.             scanf("%d", &x);
  15.             stk[0].push(x);
  16.             cout << "push 1\n";
  17.         } else if(cmd == 'd'){
  18.             if(stk[1].empty()){
  19.                 while(!stk[0].empty()){
  20.                     stk[1].push(stk[0].top());
  21.                     stk[0].pop();
  22.                     cout << "move 1 2\n";
  23.                 }
  24.             }
  25.             if(!stk[1].empty()){
  26.                 cout << "pop 2\n";
  27.                 cout << stk[1].top() << '\n';
  28.                 stk[1].pop();
  29.             }
  30.         }
  31.     }
  32.  
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement