#include<iostream>
#include<stack>
#include<string>
#pragma warning (disable:4996)

using namespace std;

#define debug(x) cout<<#x<<": "<<(x)<<endl;

int main() {

//freopen("../in1.txt","r",stdin);

string m;

stack<string> bst;
stack<string> fst;

string cur = "http://www.acm.org/";

while (cin>>m) {

if (m == "QUIT") {
break;
}

if (m == "VISIT") {
string u;
cin >> u;

bst.push(cur);
cur = u;
cout << cur << endl;

while (!fst.empty()) {
fst.pop();
}
}
else if(m=="BACK"){

if (bst.empty()) {
cout << "Ignored" << endl;
}
else {
fst.push(cur);
cur = bst.top();
bst.pop();
cout << cur << endl;
}
}
else if(m=="FORWARD"){

if (fst.empty()) {
cout << "Ignored" << endl;
}
else {
bst.push(cur);
cur = fst.top();
fst.pop();
cout << cur << endl;
}
}
}
return 0;
}

POJ1028 Web Navigation【栈模拟:按照题目的做就行】_#include