Saleh127

LO 1113

Jun 20th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4. #define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  5. int main()
  6. {
  7. Faster
  8.  
  9. int i,t=1;
  10. cin>>t;
  11. for(i=1; i<=t; i++)
  12. {
  13. cout<<"Case "<<i<<":\n";
  14. string command;
  15. stack<string>backward;
  16. stack<string>frward;
  17. string url="http://www.lightoj.com/";
  18.  
  19. while(1)
  20. {
  21. cin>>command;
  22. if(command=="QUIT") break;
  23. else if(command=="VISIT")
  24. {
  25. backward.push(url);
  26. cin>>url;
  27. while(!frward.empty())
  28. {
  29. frward.pop();
  30. }
  31. cout<<url<<endl;
  32. }
  33. else if(command=="BACK")
  34. {
  35. if(backward.empty())
  36. {
  37. cout<<"Ignored\n";
  38. }
  39. else
  40. {
  41. frward.push(url);
  42. url=backward.top();
  43. backward.pop();
  44. cout<<url<<endl;
  45. }
  46. }
  47. else if(command=="FORWARD")
  48. {
  49. if(frward.empty())
  50. {
  51. cout<<"Ignored\n";
  52. }
  53. else
  54. {
  55. backward.push(url);
  56. url=frward.top();
  57. frward.pop();
  58. cout<<url<<endl;
  59. }
  60. }
  61. }
  62. }
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment