fork download
  1.  
  2. #include<iostream>
  3.  
  4. using namespace std;
  5.  
  6. class Stack{
  7. private:
  8. int top;
  9. int capacity;
  10. int size;
  11. string *arr;
  12. public:
  13. Stack(int n){
  14. top=-1;
  15. capacity=n;
  16. size=0;
  17. arr=new string[capacity];
  18. }
  19. bool isempty()
  20. {
  21. if(top==-1)
  22. {
  23. return true;
  24. }
  25. else return false;
  26. }
  27. string push(Stack *s,string a)
  28. {
  29.  
  30. s->top++;
  31. s->arr[s->top]=a;
  32. s->size++;
  33. return arr[s->top];
  34.  
  35. }
  36. string pop(Stack *s)
  37. {
  38. if(isempty())
  39. {
  40. return "Ignored";
  41. }
  42. else{
  43. string b=s->arr[s->top];
  44. s->top--;
  45. s->size--;
  46. return b;
  47. }
  48. }
  49. string printtop()
  50. {
  51. if(top==-1)
  52. {
  53. return "Ignored";
  54. }
  55. else{
  56. string a=arr[top];
  57. return a;
  58. }
  59. }
  60. int gettop()
  61. {
  62. return top;
  63. }
  64. int sizestack(Stack *s){
  65. return s->size;
  66. }
  67. void print()
  68. {
  69. for(int i=top;i>=0;i--)
  70. {
  71. cout<<arr[i]<<endl;
  72. }
  73. }
  74. };
  75.  
  76. int main()
  77. {
  78. int kase=1,n;
  79. for(scanf("%d",&n);kase<=n;kase++)
  80. {
  81. string hold,in="http://w...content-available-to-author-only...j.com/";
  82. Stack b(100),f(100);
  83. printf("Case %d:\n",kase);
  84. b.push(&b,in);
  85. while(cin>>in)
  86. { if(in=="QUIT") break;
  87. if(in=="VISIT")
  88. {
  89. cin>>in;
  90. cout<<in<<endl;
  91. b.push(&b,in);
  92. while(!f.isempty()){
  93. f.pop(&f);
  94. }
  95. }
  96. else if(in=="BACK" && b.sizestack(&b)>1)
  97. {
  98. hold=b.printtop();
  99. b.pop(&b);
  100. cout<<b.printtop()<<endl;
  101. f.push(&f,hold);
  102. }
  103.  
  104.  
  105. else if(in=="FORWARD" && !f.isempty())
  106. {
  107. b.push(&b,f.printtop());
  108. cout<<f.printtop()<<endl;
  109. f.pop(&f);
  110. }
  111. else
  112. {
  113. cout<<"Ignored\n";
  114. }
  115. }
  116.  
  117.  
  118. }
  119.  
  120. }
  121.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty