Browse stack for simulated web pages (POJ1028)

Source: Internet
Author: User

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

Attention:

1, with two stacks to simulate, one to save can return, one to save can go forward.

2, visit method, you will be able to forward the stack empty.

3, back method, the current page to the stack can go forward, and can return the stack out of an element.

4, forward method, the current page is saved to the stack that can be returned, the stack can go forward to stack an element, into the current page.

#include <iostream>#include<stack>#include<string>using namespaceStd;stack<string>Bstack,fstack;stringCurrent ;voidvisit () {if(current!="") Bstack.push (current); CIN>>Current ; cout<<current<<Endl;  while(!fstack.empty ())///to empty the previousFstack.pop (); return;}voidBack () {if(Bstack.empty ()) {cout<<"ignored\n"; return;   } fstack.push (current); ///Put the current in the previous stackCurrent=bstack.top ();///get a new current pageBstack.pop (); cout<<current<<Endl;}voidforward () {if(Fstack.empty ()) {cout<<"ignored\n"; return;   } bstack.push (current); ///current page to present stackCurrent=fstack.top ();///The current page becomes the previous pageFstack.pop (); cout<<current<<Endl;}intMain () {stringcmd; Current="http://www.acm.org/";  while(cin>>cmd&&cmd!="QUIT")    {        if(cmd=="VISIT") visit (); Else if(cmd=="FORWARD") forward (); Else if(cmd==" Back") back (); }    return 0;}
View Code

Browse stack for simulated web pages (POJ1028)

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.