fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, st[100], top = -1;
  6. cin >> n;
  7. while (n) {
  8. int op;
  9. cin >> op;
  10. if (op == 1) {
  11. int x;
  12. cin >> x;
  13. ++top;
  14. st[top] = x;
  15. } else if (op == 2 && top >= 0) {
  16. --top;
  17. } else if (op == 3) {
  18. if (top >= 0) {
  19. cout << st[top] << endl;
  20. } else {
  21. cout << "Stiva goala" << endl;
  22. }
  23. }
  24. --n;
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0s 5316KB
stdin
4
1 10
1 20
2
3
stdout
10