#include <iostream>
#include <stack>
#include <vector>
using namespace std;
int main() {
stack<int> myStack;
// A) Add at least 10 elements into the stack
vector<int> elements = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
for (int element : elements) {
myStack.push(element);
}
// B) Remove even numbers from the stack
stack<int> tempStack;
while (!myStack.empty()) {
int topElement = myStack.top();
myStack.pop();
if (topElement % 2 != 0) {
tempStack.push(topElement);
}
}
myStack = tempStack; // Restore the stack with only odd numbers
// C) Display the content of the stack
cout << "Stack content: ";
while (!myStack.empty()) {
cout << myStack.top() << " ";
myStack.pop();
}
cout << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDx2ZWN0b3I+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgc3RhY2s8aW50PiBteVN0YWNrOwoKICAvLyBBKSBBZGQgYXQgbGVhc3QgMTAgZWxlbWVudHMgaW50byB0aGUgc3RhY2sKICB2ZWN0b3I8aW50PiBlbGVtZW50cyA9IHsxLCAyLCAzLCA0LCA1LCA2LCA3LCA4LCA5LCAxMCwgMTEsIDEyfTsKICBmb3IgKGludCBlbGVtZW50IDogZWxlbWVudHMpIHsKICAgIG15U3RhY2sucHVzaChlbGVtZW50KTsKICB9CgogIC8vIEIpIFJlbW92ZSBldmVuIG51bWJlcnMgZnJvbSB0aGUgc3RhY2sKICBzdGFjazxpbnQ+IHRlbXBTdGFjazsKICB3aGlsZSAoIW15U3RhY2suZW1wdHkoKSkgewogICAgaW50IHRvcEVsZW1lbnQgPSBteVN0YWNrLnRvcCgpOwogICAgbXlTdGFjay5wb3AoKTsKICAgIGlmICh0b3BFbGVtZW50ICUgMiAhPSAwKSB7CiAgICAgIHRlbXBTdGFjay5wdXNoKHRvcEVsZW1lbnQpOwogICAgfQogIH0KICBteVN0YWNrID0gdGVtcFN0YWNrOyAvLyBSZXN0b3JlIHRoZSBzdGFjayB3aXRoIG9ubHkgb2RkIG51bWJlcnMKCiAgLy8gQykgRGlzcGxheSB0aGUgY29udGVudCBvZiB0aGUgc3RhY2sKICBjb3V0IDw8ICJTdGFjayBjb250ZW50OiAiOwogIHdoaWxlICghbXlTdGFjay5lbXB0eSgpKSB7CiAgICBjb3V0IDw8IG15U3RhY2sudG9wKCkgPDwgIiAiOwogICAgbXlTdGFjay5wb3AoKTsKICB9CiAgY291dCA8PCBlbmRsOwoKICByZXR1cm4gMDsKfQ==