题目链接:http://poj.org/problem?

id=1028

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

Source

题意:

模拟浏览器浏览网页是前后翻页。

思路:

开两个栈。分别存储当前网页前后的网页,注意新訪问一个网页时,应该把当前网页的前面的栈清空!

代码例如以下:

#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
stack <string>b;
stack <string>f;
int main()
{
string tt = "http://www.acm.org/";
string s;
while(cin >> s)
{
if(s == "QUIT")
break;
if(s == "VISIT")
{
b.push(tt);
cin >> tt;
cout<<tt<<endl;//始终输出当前页
while(!f.empty())//当新訪问一个页面的时候把之前页面前面的清空
{
f.pop();
}
}
else if(s == "BACK")
{
if(!b.empty())
{
f.push(tt);
tt = b.top();
b.pop();
cout<<tt<<endl;//始终输出当前页
}
else
cout<<"Ignored"<<endl;
}
else
{
if(!f.empty())
{
b.push(tt);
tt = f.top();
f.pop();
cout<<tt<<endl;//始终输出当前页
}
else
cout<<"Ignored"<<endl;
}
}
return 0;
}

poj 1028 Web Navigation(模拟)的更多相关文章

  1. poj 1028 Web Navigation

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

  2. poj 1028 Web Navigation 【模拟题】

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

  3. POJ 1028 Web Navigation 题解

    考查代码能力的题目.也能够说是算法水题,呵呵. 推荐新手练习代码能力. 要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈.做多了,我就直接使用STL了. #includ ...

  4. 1028 Web Navigation

    题目链接: http://poj.org/problem?id=1028 题意: 模拟浏览器的前进/后退/访问/退出 的四个操作. 输出当前访问的URL或者Ignore(如果不能前进/后退). 分析: ...

  5. poj 1208 Web Navigation(堆栈操作)

    一.Description Standard web browsers contain features to move backward and forward among the pages re ...

  6. POJ 1028:Web Navigation

    Web Navigation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30828   Accepted: 13821 ...

  7. POJ1028 Web Navigation

    题目来源:http://poj.org/problem?id=1028 题目大意: 模拟实现一个浏览器的“前进”和“回退”功能.由一个forward stack和一个backward stack实现. ...

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

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

  9. 使用 Web API 模拟其他用户

    模拟的要求 模拟可代表另一个 Microsoft Dynamics CRM 用户,用于执行业务逻辑(代码)以便提供所需功能或服务,它使用模拟用户的相应角色和基于对象的安全性.这项技术很有必要,因为 M ...

随机推荐

  1. C++ : Boost : Rational 有理数类

    因为一些不为人知的原因, 我需要一些能减少我程序误差的东西.于是找到了这个类. 然后下载了Boost这个庞大的库. 安装与配置 在官网上找到下载地址, 大概有71MB, 下来来解压到任意位置就好了. ...

  2. Linux学习笔记:ps -ef、ps aux、kill -9

    一.查看进程命令 1.ps命令 Linux中的ps命令是Process Status的缩写. ps命令用来列出系统中当前运行的那些进程. ps命令列出的是当前那些进程的快照,就是执行ps命令的那个时刻 ...

  3. java通过POI和easypoi实现Excel的导出

    前言 在工作经常会遇到excel导出报表的功能,自己也做过一些,然后在项目里看到同事封装的一个excel导出工具类,着实不错,拿来分享一下.然后,又在网上看到一个使用easypoi实现cxcel导出的 ...

  4. Ansible playbook基础组件介绍

    本节内容: ansible playbook介绍 ansible playbook基础组件 playbook中使用变量 一.ansible playbook介绍 playbook是由一个或多个“pla ...

  5. 用html5实现的flappy-bird

    可能网上早就有几个flappy-bird的html5版本啦,到这个时候flappy-bird可能也没有之前那么火了,但是作为一个新手,自己思考,自己动手写一个flappy-bird的demo还是很有成 ...

  6. Ionic Js十三:平台

    $ionicPlatform $ionicPlatform 用来检测当前的平台,以及诸如在PhoneGap/Cordova中覆盖Android后退按钮.  

  7. thinkphp中如何是实现多表查询

    多表查询经常使用到,但如何在thinkphp中实现多表查询呢,其实有三种方法. 1 2 3 4 5 6 7 8 9 10 11 12 // 1.原生查询示例: $Model = new Model() ...

  8. jQuery的data() 和 h5 的 dataset()

    作用:获取自定义属性 命名规则:驼峰命名法  data-user==>user data-user-name==>userName 区别:jQuery:操作内存   h5: 操作DOM j ...

  9. 【原创】Linux常用脚本

    #1.启用停用VIP sudo /etc/ha.d/resource.d/IPaddr 10.10.10.10 start sudo /etc/ha.d/resource.d/IPaddr 10.10 ...

  10. iOS Sprite Kit教程之使用帮助文档以及调试程序

    iOS Sprite Kit教程之使用帮助文档以及调试程序 IOS中使用帮助文档 在编写代码的时候,可能会遇到很多的方法.如果开发者对这些方法的功能,以及参数不是很了解,就可以使用帮助文档.那么帮助文 ...