POJ 1028 Web Navigation

Source: Internet
Author: User

The subject of the ability to examine code. Can also be said to be the algorithm water problem, hehe.

Recommended for beginners to practice code skills.

To increase the difficulty of using pure C to implement the stack, then it is a bit difficult, you can use the array to simulate the ring stack. Long, I will use the STL directly.


#include <stdio.h> #include <iostream> #include <stack> #include <string>using namespace std; int main () {stack<string> forward;stack<string> backward;string cur = "http://www.acm.org/"; string cmd; while (Cin>>cmd) {if (cmd = = "QUIT") break;if (cmd = = "VISIT") {Backward.push (cur); Cin>>cur;puts (Cur.c_str () ); forward = Stack<string> ();} else if (cmd = = "Back") {if (Backward.empty ()) {puts ("ignored");} Else{forward.push (cur); cur = backward.top (); Backward.pop ();p UTS (CUR.C_STR ());}} else if (cmd = = "FORWARD") {if (Forward.empty ()) {puts ("ignored");} Else{backward.push (cur); cur = forward.top (); Forward.pop ();p UTS (CUR.C_STR ());}} return 0;}



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.