ZOJ 1061 Web Navigation
题目大意:模拟一个浏览器,打开一个网页、后退或者前进,输出网址。
解法:用两个堆栈分别表示后退保存的网页和前进保存的网页。初始化时把当前页面压入后退堆栈的栈顶。要注意几点,一个是每次记得要清空两个堆栈,另一个,如果后退之后又打开了新的网页,前进的堆栈要清空,这和真实的浏览器的结果是一致的。
参考代码:
#include<iostream>
#include<string>
#include<stack> using namespace std; stack<string> back;
stack<string> forw; int main(){
int n;
cin>>n;
while(n--){
string cmd,url="http://www.acm.org/";
while(!back.empty())
back.pop();
while(!forw.empty())
forw.pop();
back.push(url); while(1){
cin>>cmd;
if(cmd=="QUIT")break;
if(cmd=="VISIT"){
cin>>url;
back.push(url);
cout<<url<<endl;
while(!forw.empty()) //visit new website, empty the forward stack
forw.pop();
}
if(cmd=="BACK"){
if(back.size()==1) //top url is the current
cout<<"Ignored"<<endl;
else{
forw.push(url);
back.pop();
url=back.top();
cout<<url<<endl;
}
}
if(cmd=="FORWARD"){
if(forw.empty())
cout<<"Ignored"<<endl;
else{
url=forw.top();
forw.pop();
back.push(url);
cout<<url<<endl;
}
}
}
if(n>0)
cout<<endl; } return 0;
}
ZOJ 1061 Web Navigation的更多相关文章
- poj 1028 Web Navigation
Web Navigation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31088 Accepted: 13933 ...
- POJ1028 Web Navigation
题目来源:http://poj.org/problem?id=1028 题目大意: 模拟实现一个浏览器的“前进”和“回退”功能.由一个forward stack和一个backward stack实现. ...
- POJ 1028:Web Navigation
Web Navigation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30828 Accepted: 13821 ...
- POJ-1028 Web Navigation 和TOJ 1196. Web Navigation
Standard web browsers contain features to move backward and forward among the pages recently visited ...
- Web Navigation
Description Standard web browsers contain features to move backward and forward among the pages rece ...
- [POJ1028]Web Navigation(栈)
这题是01年East Central North的A题,目测是签到题 Description Standard web browsers contain features to move backwa ...
- poj 1028 Web Navigation(模拟)
题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...
- poj 1208 Web Navigation(堆栈操作)
一.Description Standard web browsers contain features to move backward and forward among the pages re ...
- POJ 1028 Web Navigation 题解
考查代码能力的题目.也能够说是算法水题,呵呵. 推荐新手练习代码能力. 要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈.做多了,我就直接使用STL了. #includ ...
随机推荐
- bzoj 2561: 最小生成树
#include<cstdio> #include<iostream> #include<cstring> #define M 100009 #define inf ...
- select2 插件
官网:http://select2.github.io/ Select2是基于jQuery的一个插件,没有引用jQuery,是没有效果的 1.在实现给select2添加placeholder效果的 ...
- 戴文的Linux内核专题:08内核配置(4)
转自Linux中国 这个第四部分里,我们将继续配置更多的设置和特性. 这里我们被问及关于"IBM Calgary IOMMU support (CALGARY_IOMMU)".这个 ...
- 读者写者问题继 读写锁SRWLock
在<秒杀多线程第十一篇读者写者问题>文章中我们使用事件和一个记录读者个数的变量来解决读者写者问题.问题虽然得到了解决,但代码有点复杂.本篇将介绍一种新方法--读写锁SRWLock来解决这一 ...
- linux下一键安装 powershell,的bash脚本
说明 目前,linux下的powershell约等于pash.希望大家专注mono,关注pash. 一键安装脚本包括for centos6,centos7,ubuntu 14.04 ubuntu 1 ...
- error: unknown field 'ioctl' specified in initializer
error message: 原因: 从2.6.36开始,file_operations结构发生了重大变化 具体看 xx../include/linux/fs.h定义: 取消了原先的 int (*i ...
- opencv 工程的保存
一个项目的保存,只要保存工程底下的.CPP .h .dll .lib 输入输出文件即可 最终保存的文件
- centos虚拟机,环境配置
yum安装 yum -y install 包名(支持*) :自动选择y,全自动yum install 包名(支持*) :手动选择y or n 1.安装vim Centos默认自带VI,功能没VIM丰富 ...
- AS启动模拟器报'mksdcard.exe' is missing from the SDK tools folder.异常、启动模拟器失败
这个问题是因为SDK下的tools文件夹中找不到mksdcard.exe程序所以无法启动模拟器,下载android-sdk_r20-windows.zip压缩包解压缩后将tools文件覆盖到SDK的t ...
- UIViewController添加子控制器(addChildViewController)
// // TaskHallViewController.m // yybjproject // // Created by bingjun on 15/10/27. // Copyright ...