POJ 1028-Web Navigation
来源:互联网 发布:正规淘宝刷平台免费 编辑:程序博客网 时间:2024/05/21 17:13
Web Navigation
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 34867 Accepted: 15579
题目链接:点击打开链接
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/
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/
BACK
BACK
BACK
FORWARD
VISIT http://www.ibm.com/
BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT
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
题意:
本题的题意很好理解,让你模仿一个栈,有四个命令BACK, FORWARD,VISIT,QUIT,本题是让你访问网站,最初你的网站地址是http://www.acm.org/,然后VISIT,这个命令后面会跟上你要访问的网址,然后对应将它输出,BACK这个命令是返回,让你输出当前网站的上一个网站地址,FORWARD这个命令是前进,是让你输出当前命令的下一个网址,对于BACK,FORWARD这两个命令,如果没有满足条件的网站就输出Ignored,然后QUIT是输入的结束,还有一点需要注意,就是如果在你返回到某一个网站地址的时候,你再用VISIT命令新访问一个网站的时候,那么以前该网站前面的网站都被抹去。
分析:
题意只要知道了,感觉心里就有数了,我用数组水过的,慢慢控制,一点点调改好的。
#include<iostream>#include<string>#include<stdio.h>#include<string.h>#include<string>#include<algorithm>using namespace std;char s[1005][75];///存网址int main(){char h[10];///存命令int k,bj=0;///bj是跟着新出现的网址走的,统计我们此时有多少个网址k=1;///保存我们当前的网站的位置memset(s,'0',sizeof(s));///这个一定要有,不然不好判断while(~scanf("%s",h)) { if(strcmp(h,"QUIT")==0)///输入结束标志 break;else if(strcmp(h,"VISIT")==0)///访问新网站{scanf("%s",s[k++]);bj++;printf("%s\n",s[k-1]);for(int i=k;i<=bj;i++)///将前面的网站都抹去 s[i][0]='0';} else if(strcmp(h,"BACK")==0)///查找该网站的上一个网站 { k--; if((k-1)<0)///说明超出边界 {printf("Ignored\n");k=1;}else if((k-1)==0)///说明该网站的上一个网站是最初的网站 printf("http://www.acm.org/\n"); else printf("%s\n",s[k-1]);}else if(strcmp(h,"FORWARD")==0)///查找该网站的下一个网站 {k++;if(s[k-1][0]=='0')///说明该网站的下一个网站没有{printf("Ignored\n");k--;}else if((k-1)==0)///说明是最初的网站 printf("http://www.acm.org/\n"); elseprintf("%s\n",s[k-1]);}}return 0;}
阅读全文
0 0
- POJ 1028 Web Navigation
- POJ 1028 Web Navigation
- poj 1028 Web Navigation
- Web Navigation poj 1028
- poj 1028 Web Navigation
- POJ-1028-Web Navigation
- poj 1028 Web Navigation
- poj-1028 Web Navigation
- POJ 1028 Web Navigation
- poj 1028 Web Navigation
- POJ 1028 Web Navigation
- POJ 1028 - Web Navigation
- POJ 1028 Web Navigation
- poj 1028 Web Navigation
- POJ 1028 Web Navigation
- POJ 1028 - Web Navigation
- POJ 1028----Web Navigation
- poj 1028-Web Navigation
- 物联网的三层框架
- 3年测试经验的文艺青年,从京东测试团队浅谈纯功能测试人员该何去何从?
- C++使用模板实现顺序表
- 关于STL之vector,deque的总结
- ios10中禁止用户缩放页面
- POJ 1028-Web Navigation
- 剑指_矩阵中的路径_回溯法
- Jackson介绍(1)-jackson2.x与Jackson1.9的比较
- log4net config
- 1328买玩具
- 十分简单-如何在局域网中将Ubuntu文件夹共享给Windows
- darwin之一万个定时器实现(IdleTask)
- 1324找最大
- 如何使用git精确定位代码的出处,作者,时间,SHA,并精确查看代码的修改记录