oi.nks.edu.cn
px.lboj.com.cn
#include <iostream>
#include <stack>
#include<string>
using namespace std;
int main()
{
stack<string> st1, st2;
string cmd;
while (true)
{
getline(cin, cmd);
if (cmd == "QUIT")
{
break;
}
if (cmd.substr(0, 4) == "VISI" && cmd.substr(0, 6) == "VISIT ")
{
st1.push(cmd.substr(6));
cout << st1.top() << endl;
}
else if (cmd == "BACK")
{
if (st1.empty())
{
cout << "Ignored" << endl;
}
else
{
st2.push(st1.top());
st1.pop();
cout << st2.top() << endl;
}
}
else if (cmd == "FORWARD")
{
if (st2.empty())
{
cout << "Ignored" << endl;
}
else
{
st2.push(st2.top());
st2.pop();
cout << st1.top() << endl;
}
}
}
return 0;
}