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/
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
题目大意:

标准的web浏览器中包含特性向后和向前移动页面最近访问了。实现这些特性的一种方法是使用两个堆栈跟踪的页面,可以达成的向后和向前移动。这个问题,你问来实现这一点。

以下命令需要支持:

:把当前页面顶部的堆栈。流行的页面的顶端向后堆栈,使其成为新的当前页面。如果向后栈为空,命令将被忽略。

转发:把当前页面向后堆栈的顶部。流行的页面的顶部堆栈,使其成为新的当前页面。如果栈是空,命令将被忽略。

访问:把当前页面顶部的向后堆栈,并使新的当前页面指定的URL。远期栈为空。

退出:退出浏览器。

假定浏览器最初加载web页面URL http://www.acm.org

        说的是栈的模拟,但是我还不能很好的理解运用栈,所以我就这样做了,调试了好半天
#include<iostream>
#include<string>
using namespace std;
int main()
{
string str[100];
string s1="http://www.acm.org/",s2;
str[0]=s1;
int q=0,ed=0;
while(1)
{cin>>s1;
if(s1=="QUIT"){break;} if(s1=="VISIT")
{
cin>>s2;
q++;
str[q]=s2;
cout<<str[q]<<endl;
ed=q; //每次添加新的url时都要让ed=q;q相当于一直指向当前所指的url下标; 而ed是最后一个输入的url下标。
}
if(s1=="BACK")
{if(q<=0){ cout<<"Ignored"<<endl;}//若把if 和 else 的条件互换,过程会变得更加繁琐;
else {cout<<str[--q]<<endl;} }
if(s1=="FORWARD")
{
if(q>=ed){ cout<<"Ignored"<<endl;}
else {cout<<str[++q]<<endl;} } } return 0;
和我思路一样的代码,总觉的人家的简单清晰很多
并且我最后一个bug还是看这个代码找到的 #include<stdio.h>
char str[200][71]={"http://www.acm.org/"};
int point=0,end=0;
void forword()
{
if(point>=end) printf("Ignored\n");//我在参考这儿的写法
else printf("%s\n",str[++point]);
}
void back()
{
if(point<=0) printf("Ignored\n");
else printf("%s\n",str[--point]);
}
void vist()
{
scanf("%s",str[++point]);
printf("%s\n",str[point]);
end=point; //在此处更新栈的最终指针
}
int main()
{
char com[10];
int g=1;
while(g)
{
scanf("%s",com);
switch(com[0])
{
case 'V':vist();break;
case 'B':back();break;
case 'F':forword();break;
default : g=0;break;
}
}
return 0;
}

  

}

  

poj-1028 -网页导航的更多相关文章

  1. jQuery背景跟随鼠标移动的网页导航

    首页 PSD模板 CSS模板 特效插件 源码下载 酷站欣赏 建站资源 建站教程 心境之旅 在线留言 设为首页 加入收藏 我要投稿 联系站长 Search     首页 PSD模板 CSS模板 特效插件 ...

  2. 网页导航栏 html + css的代码实现

    一般来讲,我们的网页导航栏是这么个模式来构建在结构上:1.首先我们需要给导航栏的div 给个类名 一般为nav2.然后就是一个无序表格 3.由于导航栏的文字一般都是链接用来跳转页面 要在li里面包含一 ...

  3. 纯CSS + 媒体查询实现网页导航特效

    纯css+媒体查询实现网页导航特效 附上效果图: 代码如下,复制即可使用: <!DOCTYPE html> <html lang="en"> <hea ...

  4. 【stack】模拟网页浏览 poj 1028

    #include<stdio.h> #include<string.h> int main() { ][]; ]; int i,depth; strcpy(s[]," ...

  5. poj 1028 Web Navigation(模拟)

    题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...

  6. poj 1028 Web Navigation 【模拟题】

    题目地址:http://poj.org/problem?id=1028 测试样例: Sample Input VISIT http://acm.ashland.edu/ VISIT http://ac ...

  7. poj 1028

    http://poj.org/problem?id=1028 题意(水):做一个游览器的历史记录. back:后退到上一个页面,当上一个页面没有时,输出ignored. forward:向前一个页面, ...

  8. iPhone X 网页导航概念

     以下内容由Mockplus团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具.   在移动应用程序设计中,选择汉堡菜单按钮还是标签栏作为导航一直是个古老的争论话题.目前看来,由于 ...

  9. poj 1028 Web Navigation

    Web Navigation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31088   Accepted: 13933 ...

  10. 为什么要使用ul li布局网站导航条?使用ul li布局网站网页导航必要性

    会布局的都知道网站导航条布局非常重要,可能一个导航条最终布局效果有时可以使用ul li列表标签布局,有时可以不用ul li布局,而是直接一个div盒子里直接放锚文本超链接的栏目名称,也能实现,看下图. ...

随机推荐

  1. iOS.Animations.by.Tutorials.v2.0汉化(二)

    翻译自:iOS.Animations.by.Tutorials.v2.0 第一节(第1章) 动画属性 现在你已经看到了动画是多么的简单,你可能很想知道你的视图控件是怎么动起来的.本节将给你一个UIVi ...

  2. Xmind8 Pro安装教程 Windows

      xmind是一款优秀的思维导图制作软件,这一点相信不用太多解释. 尤其作为测试人员导出测试用例为excel极其方便.网上xmind的破解方法加自己琢磨,重新整理了破解步骤. 亲测可以永久激活截止2 ...

  3. python函数式编程之装饰器(二)

    以前用装饰器,都是定义好了装饰器后,使用@装饰器名的方法写入被装饰函数的正上方 在这里,定义的装饰器都是没有参数的 在定义装饰器的函数的时候,没有在括号里定义参数,这就叫做无参装饰器 既然有无参装饰器 ...

  4. js随机出现2个数字

    1和2 随机出现 <script type="text/javascript"> $(function(){ if (Math.random()>0.5) { c ...

  5. alsa声卡分析alsa-utils调用过程

    如何分析tinyplay 播放音频和tinymix的过程?需要相应的工具来支持追查: 一.利用strace工具分析tinyplay和tinymix: strace -o tinyplay.log ti ...

  6. 实时Web与WebSocket实践

    引言:实时Web越来越被重视,Google.Facebook等大公司也逐渐开始提供实时性服务.实时Web将是未来最热门的话题之一.  本文选自<基于MVC的JavaScript Web富应用开发 ...

  7. SystemVerilog语言简介(二)

    6. 用户定义的类型 Verilog不允许用户定义新的数据类型.SystemVerilog通过使用typedef提供了一种方法来定义新的数据类型,这一点与C语言类似.用户定义的类型可以与其它数据类型一 ...

  8. 蜻蜓FM 涉嫌诈骗投资人和广告主源代码剖析

    本文主要内容,引用自知乎的这篇文章:如何评价蜻蜓 FM 伪造用户活跃度等数据 感谢"左莫"."任正"等热心正义的网友--左莫,任正的最早的回答猜测已经被蜻蜓FM ...

  9. Java获取当前的日期和时间

    Java获取当前的日期和时间 1.具体实现方法如下 /** * @Title:DateTime.java * @Package:com.you.model * @Description:获取当前的日期 ...

  10. JAVA 单步调试快捷键

    JAVA 单步调试快捷键以debug方式运行java程序后 (F8)直接执行程序.遇到断点时暂停:(F5)单步执行程序,遇到方法时进入:(F6)单步执行程序,遇到方法时跳过:(F7)单步执行程序,从当 ...