POJ 1028 Web Navigation (simulated problem)

Source: Internet
Author: User

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


Description

Standard Web browsers contain features to move backward and forward among the pages recently visited. One-to-implement these features is-to-use-stacks-keep track of the pages, can be reached by moving backward and forward. This problem is asked to implement.
The following commands need to be supported:
Back:push the current page on the top of the forward stack. Pop the page from the top of the backward stack, making it the new current page. If The backward stack is empty, the command is ignored.
Forward:push the current page on the top of the backward stack. Pop the page from the top of the forward stack, making it the new current page. If The forward stack is empty, the command is ignored.
Visit:push the current page on the top of the backward stack, and make the URL specified the new current page. The forward stack is emptied.
Quit:quit the browser.
Assume the browser initially loads the Web page at the URL http://www.acm.org/

Input

Input is a sequence of commands. The command keywords back, FORWARD, VISIT, and QUIT is all in uppercase. URLs have no whitespace and are at the most characters. You may assume this no problem instance requires more than the elements in each stack at any time. The end of input is indicated by the QUIT command.

Output

For each command and other than QUIT, print the URL of the current page after the command is executed if the command was not IG Nored. Otherwise, print "ignored". The output for each command should is printed on their own line. No output is produced for the QUIT command.

Sample Input

VISIT Http://acm.ashland.edu/VISIT Http://acm.baylor.edu/acmicpc/BACKBACKBACKFORWARDVISIT http://www.ibm.com/ Backbackforwardforwardforwardquit

Sample Output

http://acm.ashland.edu/http://acm.baylor.edu/acmicpc/http://acm.ashland.edu/http://www.acm.org/Ignoredhttp:// acm.ashland.edu/http://www.ibm.com/http://acm.ashland.edu/http://www.acm.org/http://acm.ashland.edu/http:// Www.ibm.com/Ignored

Source

East Central North America 2001

Test instructions

Browser browsing is a front and back page!

Ideas:

Open two stacks, respectively, store the page before and after the current page, note that when new access to a webpage, the current page should be emptied of the front of the stack!

The code is as follows:

#include <iostream> #include <algorithm> #include <string> #include <stack>using namespace std;    Stack <string>b;stack <string>f;int Main () {string tt = "http://www.acm.org/";    string S;        while (Cin >> s) {if (s = = "QUIT") break;            if (s = = "VISIT") {B.push (TT);            CIN >> TT; cout<<tt<<endl;//always outputs the current page while (!f.empty ())//When a new page is accessed, empty the previous page {F.pop            ();                }} else if (s = = "Back") {if (!b.empty ()) {F.push (TT);                tt = B.top ();                B.pop ();        cout<<tt<<endl;//always output the current page} else cout<< "ignored" <<endl;                } else {if (!f.empty ()) {B.push (TT);                tt = F.top ();                F.pop (); cout<<tt<<endl;//always output the current page} else cout<< "ignored" <<endl; }} return 0;}


POJ 1028 Web Navigation (simulated problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.