1028 Web Navigation
题目链接: http://poj.org/problem?id=1028
题意: 模拟浏览器的前进/后退/访问/退出 的四个操作. 输出当前访问的URL或者Ignore(如果不能前进/后退).
分析: 用一个vector加上当前位置索引index即可. 当进行visit一个新的URL时, 应该基于当前URL重新建立FORWORD表(清空以前的FORWORD元素即可).
教训: 操作容器时, 如果对容器进行改变, 那么对应的size()等等也要考虑变化, 否则机会出错.
#include <iostream>
#include <vector>
using namespace std;
vector<string> vs;
int main(){
string cmd;
string addr;
int index = ;
vs.push_back(string("http://www.acm.org/"));
while(cin>>cmd && cmd != "QUIT"){
if(cmd == "VISIT"){
cin>>addr;
/* 这样会wa,因为pop_back()操作会影响到for循环中的条件vs.size()的改变.
if(index != vs.size()-1){
for(int i=0;i<vs.size()-index-1;++i){
vs.pop_back();
}
}
*/
while(index < vs.size()-){
vs.pop_back();
}
vs.push_back(addr);
index++;
cout<<vs[index]<<endl;
}else if(cmd == "BACK"){
if(index==){
cout<<"Ignored"<<endl;
}else{
index--;
cout<<vs[index]<<endl;
}
}else if(cmd == "FORWARD"){
if(index==vs.size()-){
cout<<"Ignored"<<endl;
}else{
index++;
cout<<vs[index]<<endl;
}
}else{
cout<<"Ignored"<<endl;
}
}
return ;
}
-->
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 Description Standard web browsers contain features to move back ...
- 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 ...
- 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实现. ...
- 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 ...
随机推荐
- mac链接linux
连接 : ssh 用户名@主机名 -- ssh -p 22 root@47.98.164.34 上传: scp 要上传的文件名称 用户名@主机名:上传到的路径 下载: scp 用户名@主 ...
- java代码----I/O流写出整型,浮点型,
总结: package com.a.b; import java.io.*; public class fdsf { public static void main(String[] args) th ...
- Java-Runoob-高级教程:Java Applet 基础
ylbtech-Java-Runoob-高级教程:Java Applet 基础 1.返回顶部 1. Java Applet 基础 Applet 是一种 Java 程序.它一般运行在支持 Java 的 ...
- STL sort
STL的sort()算法,数据量大时采用Quick Sort,分段递归排序,一旦分段后的数据量小于某个门槛,为避免Quick Sort的递归调用带来过大的额外负荷,就改用Insertion Sort. ...
- 编译hostapd时,出现错误:/usr/bin/ld: cannot find -lnl
book@ubuntu:/work/project/wifi/04.hostapd/hostapd-2.0/hostapd$ make /usr/bin/ld: cannot find -lnl co ...
- node的socket.io类库概述
socket.io是一个简单的小类库,该类库实现的功能类似于node中的net模块所实现的功能. 这些功能包括websocket通信,xhr轮询,jsonp轮询等. socket类库可以接受所有与服务 ...
- mysql数据安全一之数据恢复案例
mysql数据安全一之数据恢复案例 --chenjianwen 应用场景:适宜开启binlog 日志功能,定时备份并使用--master-data参数备份,在某个时间点丢失数据,用于数据恢复 开篇总结 ...
- Android屏幕相关概念和适配方法
参考文档: 1.http://blog.csdn.net/carson_ho/article/details/51234308(略有修改) 2.http://www.cnblogs.com/cheng ...
- PHP如何知道一个类中所有的方法
当我们使用一个类时既没有源码也没有文档时(尤其是php扩展提供的类,比如mysqli,Redis类),我们该怎么知道这个类中提供了哪些方法,以及每个方法该怎么使用呢,此时就该PHP中强大的反射登场了, ...
- Oracle 创建表空间借鉴 保留,占版权留言告知
/*分为四步 */ /*第1步:创建临时表空间 */ create temporarytablespace user_temp tempfile 'D:\oracle\oradata\Oracle9i ...