Solution:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for(int cs = 1; cs <= t; cs++)
{
stack<string>f,b,st;
string s;
cout << "Case "<<cs<< ":\n";
st.push("http://www.lightoj.com/");
while(cin >> s)
{
if(s == "VISIT")
{
string str;
cin >> str;
cout <<str<<endl;
st.push(str);
while(!f.empty())f.pop();
}
else if(s == "BACK")
{
// cout << st.size()<<endl;
if(st.size() <= 1)
{
cout << "Ignored\n";
}
else
{
f.push(st.top());
st.pop();
cout << st.top()<<endl;
}
}
else if(s == "FORWARD")
{
if(f.size() == 0) cout << "Ignored\n";
else
{
cout << f.top()<<endl;
st.push(f.top() );
f.pop();
}
}
else break;
}
}
return 0;
}
Can you please , Explain how this Two stack pointer been working ?? How One stack pointer helping the other ?
ReplyDelete