fork download
  1. /* وَقُلْ رَبِّ زِدْنِي عِلْمًاً */
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <string>
  6. #include <iomanip>
  7. #include <stack>
  8. #include <set>
  9. #include <queue>
  10. #include <deque>
  11. #include <vector>
  12. #include <fstream>
  13. #include <cctype>
  14. #include <utility>
  15.  
  16. #define ll long long
  17. #define ld long double
  18. #define sz(v) ((int)(v).size())
  19. #define all(v) ((v).begin()),((v).end())
  20. #define setp(n) cout << fixed << setprecision(n)
  21. #define O_o ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  22. #define yes cout << "YES\n"
  23. #define no cout << "NO\n"
  24. #define fi(nn) for(ll i = 0; i < (nn); i++)
  25. #define fj(nn) for(ll j = 0; j < (nn); j++)
  26. #define fl(nn) for (ll i = nn - 1; i >= 0; i--)
  27. #define ffi(nn,mm) for(ll i = 0; i < (nn); i++)for(ll j = 0; j < (mm); j++)
  28. #define wt ll t;cin>>t;while(t--)
  29. #define null NULL
  30.  
  31. using namespace std;
  32. int main()
  33. {
  34. O_o
  35. ll q;
  36. cin >> q;
  37. stack<ll>v;
  38. while (q--) {
  39. string w;
  40. cin >> w;
  41. if (w == "push") {
  42. ll x;
  43. cin >> x;
  44. v.push(x);
  45. }
  46. else if (w == "pop") {
  47. v.pop();
  48. }
  49. else if (w == "top") {
  50. cout << v.top() << '\n';
  51. }
  52.  
  53. }
  54. return 0;
  55. }
Success #stdin #stdout 0.01s 5276KB
stdin
10
push 5
top
push 6
top
push 3
top
pop
top
pop
top
stdout
5
6
3
6
5