Skip to content

Instantly share code, notes, and snippets.

@Nahiduzzaman
Created February 7, 2016 15:19
Show Gist options
  • Save Nahiduzzaman/289db0512afb83b02109 to your computer and use it in GitHub Desktop.
Save Nahiduzzaman/289db0512afb83b02109 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main()
{
int t,b=1,f=0,g=0,vc=0,temp = 0,fc = 0;
string s1;
string s2 = "BACK";
string s3 = "FORWARD";
string s4 = "QUIT";
string s5 = "VISIT";
char s6[50];
string address[99];
string show[99];
int count = 0;
int counter = 0;
cin>>t;
for(int i = 0; i < t ; i ++)
{
for (int line = 0 ; line < 100 ; line ++)
{
count++;
// cout<<"\ncount"<<count;
address[0] = "http://www.lightoj.com";
show[0] = address[0];
counter++; // FOR PRINT
// cout <<" "<<counter;
// line++;
f = line + 1;
cin >> s1;
// cout <<"Line= "<<line;
if (s1.compare(s5) == 0) //visit
{
cin>>s6;
address[f] = s6;
show[f] = address[f];
cout << "f = " << f;
g = f;
vc++;
}
else if (s1.compare(s2)==0) //back
{
// counter--;
cout << "f =" << f;
g--;
cout << "\ng=" << g;
if (g < 0)
{
show[f] = "Ignored";
}
else{
show[f] = address[g];
}
}
else if (s1.compare(s3)==0) //forward
{
cout << "f =" << f;
g++;
cout << "\ng=" << g;
cout<<"\nvc = "<<vc;
if (g > vc)
{
show[f] = "Ignored";
}
else if (g < 0 || g == 0)
{
g=1;
show[f] = address[g];
}
else{
show[f] = address[g];
}
}
else if (s1.compare(s4)==0) //quit
{
break;
}
}
cout<< "Case" << i+1 <<":" <<endl;
for (int m = 0 ; m < count; m++)
{
cout << show[m+1]<<endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment