POJ 1028 Web Navigation

來源:互聯網
上載者:User

Description

Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward. In this problem, you are asked to implement this.
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 that 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 are all in uppercase. URLs have no whitespace and have at most 70 characters. You may assume that no problem instance requires more than 100 elements in each stack at any time. The end of input is indicated by the QUIT command.

Output

For each command other than QUIT, print the URL of the current page after the command is executed if the command is not ignored. Otherwise, print "Ignored". The output for each command should be printed on its 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
#include<iostream>#include<cstring>using namespace std;int main(){int i = 0,max = 0;//max 記錄URL儲存的總個數,i是浮動的,再各網頁之間跳動char URL[1000][100],command[10];//URL[0]儲存首頁,真鬱悶,不知道怎麼在二維數組中寫入字串URL[0][0] ='h';URL[0][1] ='t';URL[0][2] ='t';URL[0][3] ='p';URL[0][4] =':';URL[0][5] ='/';URL[0][6] ='/';URL[0][7] ='w';URL[0][8] ='w';URL[0][9] ='w';URL[0][10] ='.';URL[0][11] ='a';URL[0][12] ='c';URL[0][13] ='m';URL[0][14] ='.';URL[0][15] ='o';URL[0][16] ='r';URL[0][17] ='g';URL[0][18] ='/';URL[0][19] ='/0';while(scanf("%s",command)){if(command[0] == 'V'){++i;max = i;scanf("%s",URL[max]);printf("%s/n",URL[max]);if(i> max) max = i;}if(command[0] == 'B'){if(i>=0)i--;//控制好浮動i的加減if(i < 0){printf("Ignored/n");++i;}elseprintf("%s/n",URL[i]);}if(command[0] == 'F'){if(i<=max) ++i;if( i > max){printf("Ignored/n");--i;}elseprintf("%s/n",URL[i]);}if(command[0] == 'Q'){return 0;}}return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.