fork download
  1. #include <cstdio>
  2.  
  3. typedef int Bool;
  4. #define MAX 100
  5.  
  6. class Stack {
  7. protected:
  8. int Top, S[MAX];
  9.  
  10. public:
  11. void push(int e) {
  12. S[--Top] = e;
  13. return;
  14. }
  15.  
  16. int pop() {
  17. return S[Top++];
  18. }
  19.  
  20. Bool empty() {
  21. return Top == MAX;
  22. }
  23.  
  24. Stack() {
  25. Top = MAX;
  26. }
  27. };
  28.  
  29. class WindowStack : public Stack {
  30. protected:
  31. int Window;
  32.  
  33. public:
  34. void Start() {
  35. Window = Top;
  36. return;
  37. }
  38.  
  39. int LookUp() {
  40. return S[Window++];
  41. }
  42.  
  43. Bool Bottom() {
  44. return Window == MAX;
  45. }
  46.  
  47. WindowStack() {
  48. return;
  49. }
  50. };
  51.  
  52. int main() {
  53. int x;
  54. WindowStack s = WindowStack();
  55.  
  56. while (scanf("%d", &x) != EOF)
  57. s.push(x);
  58.  
  59. s.Start();
  60.  
  61. printf("%d ", s.LookUp());
  62. printf("%d\n", s.LookUp());
  63.  
  64. while (!s.empty())
  65. printf("%d ", s.pop());
  66.  
  67. printf("\n");
  68. }
Success #stdin #stdout 0s 544KB
stdin
5 4 3 2 1 
stdout
1 2
1 2 3 4 5