Advertisement
NHumme

Untitled

Oct 31st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <vector>
  6. #include <string>
  7. #include <set>
  8. #include <stack>
  9. #include <queue>
  10. #include <deque>
  11. using namespace std;
  12.  
  13. #define TASK "stack"
  14.  
  15. int a[2000000], fr = 0;
  16.  
  17. void push(int x) {
  18. a[fr] = x;
  19. fr++;
  20. }
  21.  
  22. void pop() {
  23. fr--;
  24. }
  25.  
  26. int top() {
  27. return a[fr - 1];
  28. }
  29.  
  30. int main() {
  31.  
  32. #ifdef _DEBUG
  33. freopen("debug.in", "r", stdin);
  34. freopen("debug.out", "w", stdout);
  35. #else
  36. freopen(TASK".in", "r", stdin);
  37. freopen(TASK".out", "w", stdout);
  38. #endif // _DEBUG
  39.  
  40. int m, t;
  41. char c;
  42. cin >> m;
  43. for (int i = 0; i < m; i++) {
  44. cin >> c;
  45. if (c == '-') {
  46. cout << top() << "\n";
  47. pop();
  48. }
  49. else {
  50. cin >> t;
  51. push(t);
  52. }
  53. }
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement