Web Navigation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 32963   Accepted: 14704

->   Link   <-

本来这种题意一目了然的题就得一遍过的,无奈很多小细节出了问题,表示只要照着题目告诉你的写就可以过了;

还有英语是硬伤!!!

题意:一个浏览器初始网址是”http://www.acm.org/“,当浏览新网页时就会有历史记录(就用我们平时用的来讲吧更好理解),我们回去浏览某个历史网页时刚刚浏览的网页就变成前一个网页了,(比如UC右键右滑是前进,左滑是后退),当我们浏览的是最新打开的网页时前进是无效的,而后退有效,当退回初始页面时再后退也无效了,反而前进有效回到刚才的页面;本题就是这个意思,然后输入一连串指令要我们求出当前网页网址;

思路:实际上题目已经告诉我们怎么做了;开两个栈,一个backward,一个forward,操作如下:

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. 后退操作:先判断backward栈是否为空,是则忽视此操作,否则将当前页面存入forward栈中,然后将backward栈顶取出成为当前页面;

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. 前进操作:先判断forward栈是否为空,是则忽视此操作,否则将当前页面存入backward栈中,然后将forward栈顶取出成为当前页面;

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. 输入结束标志;

只要操作有效(前进或后退不为空)则输出当前页面;

string ask,cur;
int main()
{
stack<string>before;
stack<string>ward;
cur="http://www.acm.org/";
while(cin>>ask&&ask[0]!='Q')
{
if(ask[0]=='V')打开新网页;
{
ward.push(cur);
while(!before.empty())//前进无效了,所以before栈清空;
before.pop();
cin>>cur;
cout<<cur<<endl;
}
else if(ask[0]=='B')
{
if(ward.empty())//先判断是否为空,不然WA,博主就是跪在这里;
cout<<"Ignored"<<endl;
else
{
before.push(cur);
cur=ward.top();
ward.pop();
cout<<cur<<endl;
}
}
else if(ask[0]=='F')
{
if(before.empty())
cout<<"Ignored"<<endl;
else
{
ward.push(cur);
cur=before.top();
before.pop();
cout<<cur<<endl;
}
}
}
return 0;
}

最新文章

  1. C语言 经典编程100题
  2. 解决ASP.NET Core Mvc文件上传限制问题
  3. Unit Test测试框架中的测试的执行顺序
  4. examine self thrice a day2017
  5. reporting services rdl文件如何不分页
  6. Ext treelist 动态切换TreeStore
  7. supersr--addSubview和 insertSubView 区别
  8. c# 中get和post的方法
  9. extjs tips
  10. shell之变量与read
  11. 史上最全Java表单验证封装类
  12. FineUI Grid控件右键菜单的实现
  13. Java基础笔记-面向对象2
  14. 【原创】leetCodeOj --- Dungeon Game 解题报告
  15. 怎么解决dede首页网址自动加上index.html
  16. 浅谈Android进阶之路
  17. Hadoop介绍
  18. C# - 操作符
  19. Units about ASM
  20. Atcode ABC105-C:Base -2 Number

热门文章

  1. Kruskal算法 分类: c/c++ 算法 2014-10-01 17:09 540人阅读 评论(0) 收藏
  2. apache-storm-1.0.2.tar.gz的集群搭建(3节点)(图文详解)(非HA和HA)
  3. C++中的数学函数汇总
  4. Android开发学习——ButterKnife使用
  5. js类、原型——学习笔记
  6. SpringSecurity的简单使用
  7. flex弹性布局操练2
  8. CSS3 动画-- 鼠标移上去,div 会旋转、放大、移动
  9. H5 canvas 之乱画
  10. oracle数据库使用hint来让模糊查询走索引