Saturday, 19 September 2015

LightOJ 1113 – Discover the Web_Solution

//Tanzila Islam

//Southeast University

//mail : tanzilamohita@gmail.com


#include <iostream>

using namespace std;


const int MAX_SIZE = 10000;

class Stack {

private:

    string array[MAX_SIZE];

    int top;


public:

    Stack() {

        top = 0;

    }


    void push(string x) {

        array[top] = x;

        top++;

    }


    string pop() {

        top--;

        return array[top];

    }


    string peek() {

        return array[top - 1];

    }


    bool isEmpty() {

        if (top == 0)

            return true;

        else return false;

    }

};


int main() {


    int t;

    cin >> t;

    for(int i = 1; i<=t;i++){

            cout << "Case "  <<i <<":" << endl;


        Stack FORWARD, BACK;


        string s;

        string recenturl = "http://www.lightoj.com/";


        while( cin >> s){

            if( s == "QUIT"){

                break;

            } else if( s == "VISIT"){

                string url;

                cin >> url;


                BACK.push(recenturl);

                recenturl = url;


                while( FORWARD.isEmpty() == false) {

                    FORWARD.pop();

                }

                cout << recenturl << endl;

            } else if ( s == "FORWARD" ){


                if( FORWARD.isEmpty() ){

                    cout << "Ignored" << endl;

                    continue;

                }



                BACK.push(recenturl);


                recenturl = FORWARD.pop();

                cout << recenturl << endl;


            } else {


                if( BACK.isEmpty() ){

                    cout << "Ignored" << endl;

                    continue;

                }


                FORWARD.push(recenturl);


                recenturl = BACK.pop();

                cout << recenturl << endl;

            }

        }

    }

    return 0;

}

No comments:

Post a Comment