Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <stack>
- using namespace std;
- int main()
- {
- stack <int> mystack1;
- stack <int> mystack2;
- cout << "enter the number of stack members" << '\n';
- int n;
- cin >> n;
- cout << "enter the elements of the stack " << '\n';
- for (int i = 1; i <= n; i++)
- {
- int t;
- cin >> t;
- mystack1.push(t);
- }
- if (n % 2 == 0)
- cout << "the stack is missing three middle elements " << '\n';
- else
- {
- for (int i = 0; i < n/2 - 1 ; i++)
- {
- int k = mystack1.top();
- mystack2.push(k);
- mystack1.pop();
- }
- for (int i = n / 2 - 1; i <= n / 2 + 1; i++)
- {
- int k = mystack1.top();
- mystack2.push(3 * k);
- mystack1.pop();
- }
- while (!mystack1.empty())
- {
- int k = mystack1.top();
- mystack2.push(k);
- mystack1.pop();
- }
- while (!mystack2.empty())
- {
- cout << mystack2.top() << ' ';
- mystack2.pop();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement