Advertisement
awsmpshk

Untitled

Apr 21st, 2020
554
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stack>
  3.  
  4. using namespace std;
  5.  
  6. void printStack(stack<int> st)
  7. {
  8.   while(st.size() != 0)
  9.   {
  10.     out << st.top() << " ";
  11.     st.pop();
  12.   }
  13.   out << endl;
  14. }
  15.  
  16. void mergeStacks(stack<int>& s1, stack<int>& s2)
  17. {
  18.   while (s2.size() != 0)
  19.   {
  20.     s1.push(s2.top());
  21.     s2.pop();
  22.   }
  23. }
  24.  
  25. void changeStack(stack<int> st)
  26. {
  27.   stack<int> help;
  28.   int cnt = st.size();
  29.   while (cnt != 0)
  30.   {
  31.     help.push(st.top());
  32.     if (st.top() % 2 == 0) help.push(st.top());
  33.     st.pop();
  34.   }
  35.   mergeStacks(st, help);
  36. }
  37.  
  38. int main()
  39. {
  40.   stack<int> st;
  41.   int x;
  42.  
  43.   while (cin >> x) st.push(x);
  44.  
  45.   printStack(st);
  46.   changeStack(st);
  47.   printStack(st);
  48.  
  49.   return 0;
  50. }
Advertisement
RAW Paste Data Copied
Advertisement