Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <stack>
- using namespace std;
- int main()
- {
- stack<int> stackForPopEl;
- stack<int> stackForPushEl;
- unsigned int n;
- int x;
- int type;
- std::cin >> n;
- for (size_t i = 0; i < n; ++i)
- {
- std::cin >> type;
- if (type == 1)
- {
- std::cin >> x;
- stackForPushEl.push(x);
- }
- else if (type == 2)
- {
- if((!stackForPopEl.empty() && !stackForPushEl.empty())
- ||(!stackForPopEl.empty() && stackForPushEl.empty()))
- {
- stackForPopEl.pop();
- }
- else if (stackForPopEl.empty() && !stackForPushEl.empty())
- {
- while(!stackForPushEl.empty())
- {
- stackForPopEl.push(stackForPushEl.top());
- stackForPushEl.pop();
- }
- stackForPopEl.pop();
- }
- }
- else
- {
- if((stackForPopEl.empty() && !stackForPushEl.empty())
- || (!stackForPopEl.empty() && stackForPushEl.empty()))
- {
- while(!stackForPushEl.empty())
- {
- stackForPopEl.push(stackForPushEl.top());
- stackForPushEl.pop();
- }
- std::cout << stackForPopEl.top() << std::endl;
- }
- else if (!stackForPopEl.empty() && !stackForPushEl.empty())
- {
- std::cout << stackForPopEl.top() << std::endl;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement