Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <stack>
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12. stack<int> stackForPopEl;
  13. stack<int> stackForPushEl;
  14. unsigned int n;
  15. int x;
  16. int type;
  17. std::cin >> n;
  18. for (size_t i = 0; i < n; ++i)
  19. {
  20. std::cin >> type;
  21. if (type == 1)
  22. {
  23. std::cin >> x;
  24. stackForPushEl.push(x);
  25. }
  26. else if (type == 2)
  27. {
  28. if((!stackForPopEl.empty() && !stackForPushEl.empty())
  29. ||(!stackForPopEl.empty() && stackForPushEl.empty()))
  30. {
  31. stackForPopEl.pop();
  32. }
  33. else if (stackForPopEl.empty() && !stackForPushEl.empty())
  34. {
  35. while(!stackForPushEl.empty())
  36. {
  37. stackForPopEl.push(stackForPushEl.top());
  38. stackForPushEl.pop();
  39. }
  40. stackForPopEl.pop();
  41. }
  42. }
  43. else
  44. {
  45. if((stackForPopEl.empty() && !stackForPushEl.empty())
  46. || (!stackForPopEl.empty() && stackForPushEl.empty()))
  47. {
  48. while(!stackForPushEl.empty())
  49. {
  50. stackForPopEl.push(stackForPushEl.top());
  51. stackForPushEl.pop();
  52. }
  53. std::cout << stackForPopEl.top() << std::endl;
  54. }
  55. else if (!stackForPopEl.empty() && !stackForPushEl.empty())
  56. {
  57. std::cout << stackForPopEl.top() << std::endl;
  58. }
  59.  
  60. }
  61. }
  62. return 0;
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement