模拟题目所述的浏览器的各种操作,使用一个curWebsite变量来保存当前的Page。
/*
Problem: 1028 User: DragonKnight
Memory: 712K Time: 79MS
Language: G++ Result: Accepted
*/
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main()
{
string command, website;
stack<string> back,forward;//前进栈,后退栈
string curWebsite = "http://www.acm.org/";//初始载入的页面
while(cin >> command)
{
if(command == "QUIT")
{
break;
}
else if(command == "VISIT")
{
cin >> website;
back.push(curWebsite);
curWebsite = website;
cout << curWebsite << endl;
while(!forward.empty()) forward.pop();
}
else if(command == "BACK")
{
if(!back.empty())
{
forward.push(curWebsite);
curWebsite = back.top();
back.pop();
cout << curWebsite << endl;
}
else
{
cout << "Ignored" << endl;
}
}
else if(command == "FORWARD")
{
if(!forward.empty())
{
back.push(curWebsite);
curWebsite = forward.top();
forward.pop();
cout << curWebsite << endl;
}
else
{
cout << "Ignored" << endl;
}
}
}
return 0;
}