Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>      
  3. #include <stack>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     stack <int> mystack1;
  9.     stack <int> mystack2;
  10.  
  11.     cout << "enter the number of stack members" << '\n';
  12.     int n;
  13.     cin >> n;
  14.     cout << "enter the elements of the stack " << '\n';
  15.  
  16.     for (int i = 1; i <= n; i++)
  17.     {
  18.         int t;
  19.         cin >> t;
  20.         mystack1.push(t);
  21.     }
  22.  
  23.     if (n % 2 == 0)  
  24.     cout << "the stack is missing three middle elements " << '\n';
  25.     else
  26.     {
  27.         for (int i = 0; i < n/2 - 1 ; i++)
  28.         {
  29.             int k = mystack1.top();
  30.             mystack2.push(k);
  31.             mystack1.pop();
  32.         }
  33.  
  34.         for (int i = n / 2 - 1; i <= n / 2 + 1; i++)
  35.         {
  36.             int k = mystack1.top();
  37.             mystack2.push(3 * k);
  38.             mystack1.pop();
  39.         }
  40.  
  41.         while (!mystack1.empty())
  42.         {
  43.             int k = mystack1.top();
  44.             mystack2.push(k);
  45.             mystack1.pop();
  46.         }
  47.  
  48.         while (!mystack2.empty())
  49.         {
  50.             cout << mystack2.top() << ' ';
  51.             mystack2.pop();
  52.         }
  53.      
  54.     }
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement