POJ 1028 Web Navigation

http://poj.org/problem?id=1028

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
const int inf = 8E8;
stack<string> backstack;
stack<string> forwardstack;
string cur;
string cmd;
int main()
{
    cur ="http://www.acm.org/";

    while (cin>>cmd)
    {
        if (cmd=="QUIT")
        {
            break;
        }
        if (cmd=="BACK")
        {
            if (backstack.empty())
            {
                cout<<"Ignored"<<endl;
                continue;
            }
            forwardstack.push(cur);
            cur=backstack.top();
            backstack.pop();
            cout<<cur<<endl;
        }
        if (cmd=="FORWARD")
        {
            if (forwardstack.empty())
            {
                cout<<"Ignored"<<endl;
                continue;
            }
            backstack.push(cur);
            cur=forwardstack.top();
            forwardstack.pop();
            cout<<cur<<endl;
        }
        if (cmd=="VISIT")
        {
            backstack.push(cur);

            cin>>cur;
            while (!forwardstack.empty())  forwardstack.pop();
            cout<<cur<<endl;

        }
    }


    return 0;
}

 

posted @ 2015-07-08 10:08  111qqz  阅读(150)  评论(0编辑  收藏  举报