fork download
  1. /// Spoj Easy Stack
  2. #include <bits/stdc++.h>
  3. #define X first
  4. #define Y second
  5. #define pb push_back
  6. using namespace std;
  7. typedef long long ll;
  8. typedef pair <int,int> ii;
  9. typedef pair <int,ii> i_ii;
  10. typedef vector <int> vi;
  11. typedef vector <ii> vii;
  12.  
  13. const int maxn=102;
  14. const ll MOD=1000000007;
  15.  
  16. stack <int> st;
  17. int T;
  18.  
  19. int main()
  20. {
  21. // freopen("nhap.inp", "r", stdin);
  22. scanf("%d",&T);
  23. while (T--)
  24. {
  25. int type,x;
  26. scanf("%d",&type);
  27. if (type == 1)
  28. {
  29. scanf("%d",&x);
  30. st.push(x);
  31. }
  32. if (type == 2 && !st.empty())
  33. st.pop();
  34. if (type == 3)
  35. if (st.empty()) printf("Empty!\n");
  36. else printf("%d\n",st.top());
  37. }
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0s 4572KB
stdin
Standard input is empty
stdout
Standard output is empty