pku acm 1028

#include <iostream>
#include <cstdio>
#include <string>
#include <stack>
using namespace std;

class Navigation
{
private:
	stack<string> fward;
	stack<string> bward;
	string curl;//current url
public:
	Navigation(string url):curl(url){}
	string getUrl(string cmd,string url)
	{
		if(cmd == "BACK")
			return back();
		else if(cmd == "FORWARD")
			return forward();
		else if(cmd == "VISIT")
			return visit(url);
	}
private:
	string back()
	{
		if(bward.empty())
			return "Ignored";
		fward.push(curl);		
		curl = bward.top();
		bward.pop();
		return curl;
	}

	string forward()
	{
		if(fward.empty())
			return "Ignored";
		bward.push(curl);		
		curl = fward.top();
		fward.pop();
		return curl;
	}

	string visit(string url)
	{
		bward.push(curl);
		curl = url;
		while(!fward.empty())
			fward.pop();
		return curl;
	}
};

int main()
{	
	freopen("in.txt","r",stdin);

	string cmd,url;
	Navigation nav("http://www.acm.org/");
	while(cin>>cmd)
	{		
		if(cmd == "QUIT")
			break;
		if(cmd == "VISIT")
			cin>>url;
		cout<<nav.getUrl(cmd,url)<<endl;
	}
	return 1;
}


你可能感兴趣的:(pku acm 1028)