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