1028 Web Navigation

Describe
a standard Web browser includes moving back and forth between pages recently visited function. One way to achieve these two functions are used to track the page stack by moving back and forth can be reached. In this problem, you will be asked to implement this feature.
The need to support the following command:
the BACK: The top of the current page to push forward the stack. Pop-up pages from the top of the stack, making it the new current page. If, after the stack is empty, the command is ignored.
FORWARD: Push the current page to the top of the stack to the rear. Front page pops up to the top of the stack, making it the new current page. If the stack is empty before, it ignores the command.
Access: to the top of the stack is pushed to after the current page, and the URL designated as the new current page. Before blanking the stack.
Exit: Exit browser.
Assuming that the browser initially loads the page on the URL http://www.acm.org/
input
input is a series of commands. Command keyword BACK, FORWARD, VISIT and QUIT are in uppercase. URL with no spaces and a maximum of 70 characters. You can not assume any questions instance needs of each stack more than 100 elements at any time. Enter the ending is indicated by the QUIT command.
Output
For each commands except QUIT, if not ignore the command, then print the current page URL after executing the command. Otherwise, print "ignored." Each output of the command should be printed on its own line. QUIT command output is not generated.

Sample input

VISIT http://acm.ashland.edu/
VISIT http://acm.baylor.edu/acmicpc/
BACK
BACK
BACK
FORWARD
VISIT http://www.ibm.com/
BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT

Sample Output

http://acm.ashland.edu/
http://acm.baylor.edu/acmicpc/
http://acm.ashland.edu/
http://www.acm.org/
Ignored
http://acm.ashland.edu/
http://www.ibm.com/
http://acm.ashland.edu/
http://www.acm.org/
http://acm.ashland.edu/
http://www.ibm.com/
Ignored
#include<iostream>
#include<string>
#include<stack>
using namespace std;
 
int main ()
{
    stack<string> s1,s2;
    string cmd,URL;
    s1.push("http://www.acm.org/");
    while(cin>>cmd)
    {
        if(cmd[0]=='Q')
            break;
        else if(cmd[0]=='V')
        {
            cin >> URL;
            s1.push(URL);
            cout << the URL of << endl;
             the while (! s2.empty ())        // Note that you want to s2 empty 
                s2.pop ();
        }
        else if(cmd[0]=='B')
        {
            IF (s1.size ()> 1 )           // Note that this is greater than 1, i.e., there must be two or more elements of the job 
            {                        // because the top element s1 current page is accessed, step back must return the current top of the stack to the next element of     
                s2.push (s1.top ());             
                s1.pop();
                cout<<s1.top()<<endl;
            }
            else
                cout<<"Ignored"<<endl;
        }
        else
        {
            if(!s2.empty())
            {  
                s1.push(s2.top());
                cout<<s2.top()<<endl;
                s2.pop();
            }
            else
                cout<<"Ignored"<<endl;
        }
    }
    return 0;
}

Source: https: //www.cnblogs.com/dongsheng/archive/2012/08/02/2619314.html

Guess you like

Origin www.cnblogs.com/sweet-ginger-candy/p/11518211.html