#include #include "Stack.h" #include using namespace std; int main() { ifstream in("input.txt"); ofstream out("output.txt"); Stack s1; int n; cin >> n; while (in >> n) { s1.Push(n); } while (!s1.Empty()) { if (s1.Top() % 2 == 0) { int j = s1.Top() * 2; s1.Pop(); s1.Push(j); } out << s1.Top() << " "; s1.Pop(); } in.close(); out.close(); return 0; } /*********************STACK.h****************************************/ using namespace std; template class Stack { private: struct Element { Item inf; Element *next; Element(Item x, Element *p) : inf(x), next(p) {} }; Element *head; public: Stack() : head(0) {} bool Empty() { return head == 0; } Item Pop() { if (Empty()) { return 0; } else { Element *r = head; Item i = r->inf; head = r->next; delete r; return i; } } void Push(Item data) { head = new Element(data, head); } Item Top() { if (Empty()) { return 0; } else { return head->inf; } } }; /**************************************************************************/