poj 1028 Web Navigation(模拟)
id=1028
Description
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
The end of input is indicated by the QUIT command.
Output
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(模拟)的更多相关文章
- poj 1028 Web Navigation
Web Navigation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31088 Accepted: 13933 ...
- poj 1028 Web Navigation 【模拟题】
题目地址:http://poj.org/problem?id=1028 测试样例: Sample Input VISIT http://acm.ashland.edu/ VISIT http://ac ...
- POJ 1028 Web Navigation 题解
考查代码能力的题目.也能够说是算法水题,呵呵. 推荐新手练习代码能力. 要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈.做多了,我就直接使用STL了. #includ ...
- 1028 Web Navigation
题目链接: http://poj.org/problem?id=1028 题意: 模拟浏览器的前进/后退/访问/退出 的四个操作. 输出当前访问的URL或者Ignore(如果不能前进/后退). 分析: ...
- poj 1208 Web Navigation(堆栈操作)
一.Description Standard web browsers contain features to move backward and forward among the pages re ...
- POJ 1028:Web Navigation
Web Navigation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30828 Accepted: 13821 ...
- POJ1028 Web Navigation
题目来源:http://poj.org/problem?id=1028 题目大意: 模拟实现一个浏览器的“前进”和“回退”功能.由一个forward stack和一个backward stack实现. ...
- 【stack】模拟网页浏览 poj 1028
#include<stdio.h> #include<string.h> int main() { ][]; ]; int i,depth; strcpy(s[]," ...
- 使用 Web API 模拟其他用户
模拟的要求 模拟可代表另一个 Microsoft Dynamics CRM 用户,用于执行业务逻辑(代码)以便提供所需功能或服务,它使用模拟用户的相应角色和基于对象的安全性.这项技术很有必要,因为 M ...
随机推荐
- Centos之字符串搜索命令grep
grep [选项] 字符串 文件名 在文件当中匹配符合条件的字符串 选项: -i 忽略大小写 -v 排除指定字符串 [root@localhost ~]# grep "work" ...
- 编程六月定律 | 外刊IT评论网
编程六月定律 上周,我被迫对一个很老的项目做一些修改.麻烦是,当开始着手时,我真的记不清这个项目究竟有多老了. 这实际上是我使用Codeigniter实现的第一个MVC项目.打开项目文件后,很多东西都 ...
- CTF常用python库PwnTools的使用学习
之前主要是使用zio库,对pwntools的了解仅限于DynELF,以为zio就可以取代pwntools.后来发现pwntools有很多的高级用法都不曾听说过,这次学习一下用法,希望可以在以后的exp ...
- Phoenix的安装使用与SQL查询HBase
一. Phoenix的简介 1. 什么是phoenix 现有hbase的查询工具有很多如:Hive,Tez,Impala,Shark/Spark,Phoenix等.今天主要说Phoenix.phoen ...
- linux 101 hacks 6history 及相关关键字
如果你经常使用命令行,那么有效的使用命令历史机制将会使效率获得极大提升.事实上,一旦你掌握了我在下面给出的 15 个例子, 你就会发现使用命令行将更有乐趣 是吗?我学一学呢 技巧 50:使用 HIST ...
- USACO 4.3 Letter Game (字典树)
Letter GameIOI 1995 Figure 1: Each of the 26 lowercase letters and its value Letter games are popula ...
- 基于 Struts2 的单文件和多文件上传
文件的上传下载是 Web 开发中老生常谈的功能,基于 Struts2 框架对于实现这一功能,更是能够给我们带来很多的便利.Struts2 已经有默认的 upload 拦截器.我们只需要写参数,它就会自 ...
- HBase结合MapReduce批量导入(HDFS中的数据导入到HBase)
HBase结合MapReduce批量导入 package hbase; import java.text.SimpleDateFormat; import java.util.Date; import ...
- Ubuntu16.04下HBase的安装与配置
一.环境 os : Ubuntu 16.04 LTS 64bit jdk : 1.8.0_161 hadoop : mysql : hive : hbase: -hadoop2 安装HBase前,系统 ...
- Little Elephant and Array 线段树
题目:http://codeforces.com/problemset/problem/220/B 题意 给定一组数据,多次询问区间内某数字出现次数与该数字数值相同的数的个数 思路 一看到区间查询,就 ...