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 ...
随机推荐
- web api control注册及重写DefaultHttpControllerSelector、ApiControllerActionSelector、ApiControllerActionInvoker
namespace EWorkpal.WebApi { public class HttpNotFoundDefaultHttpControllerSelector : DefaultHttpCont ...
- visualSVN server库迁移
首先,VisualSVN Server Manager,包含两个路径,一个是安装路径,例如本机:C:\Program Files\VisualSVN Server,一个是库路径,例如本机:C:\Rep ...
- ubuntu下的第一个脚本file.sh
1.新建空文档,写入shell命令: #!/bin/sh cd /home/plg ./usb 第一行一定要有,一开始参考网上写的#!/usr/bin/sh,会提示错误 bash: ./file.sh ...
- 哪些字符需要urlencode编码?具体怎么处理?
哪些字符需要urlencode编码?具体怎么处理? JS用escape()/encodeURI()/encodeURIComponent()方法编码,用unescape()/decodeURI()/e ...
- Android ContentProvider的实现
当Android中的应用需要访问其他应用的数据时,用ContentProvider可以很好的解决这个问题.今天介绍一下ContentProvider的用法. 首先开发ContentProvider有两 ...
- acvitity的日常 启动模式(上)
1. 基本介绍 大家平时只要懂一点Android知识的话,都一定会知道,一个应用的组成,往往包含了许多的activity组件,每个activity都应该围绕用户的特定动作进行跳转设计.比如说,一个电话 ...
- char 数组和 int 之间转化
上周工作结束,来到斯凯网络也将近半个月来. 没有新人的感念,最多的是将自己当作一个战士. 废话不多说,直接入正题,在没有仔细考虑问题之前我们总会 觉得:这尼玛的有毛线难度啊,不就是一个 int 转为c ...
- jQuery 常用动画
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 理解Mac和iOS中的 Event 处理
根据现在的理解,我把event处理分为5部分,第一是,Event处理的Architecture:第二是,Event的Dispatch到first responder之前: 第三是,Event从firs ...
- Ant、Maven、Gradle
android Gradle project http://www.ibm.com/developerworks/cn/opensource/os-cn-gradle/ http://www.voge ...