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 ...
随机推荐
- android之ffmpeg:设置cygwin
开发android ndk 的时候需要一个编译工具编译c程序,ndk需要linux下编译,所以win环境下提供Cygwin模拟linux编译C android-ndk 较低版本的这个工具的配置网上很多 ...
- 初学者手册-IDEA中的Git
1.Git的更新.提交.还原 IDEA中Git的更新.提交.还原方法 2.设置Git的提交方式为http 3.
- python学习(二十三) String(下) 分片和索引
分片: 记住, 是开闭区间. a = "abcdef"print(a[:])print(a[1:])print(a[:3])print(a[-2])print(a[:-2])pri ...
- WP8 MVVM设计模式
类似了Android里边的MVC模式, Windows Phone 有自己的Model-View-ViewModel模式,这种模式的作用就是为了Data和UI分离开来. 如果你英文较好的话,你可以不再 ...
- spring 配置双数据源并读写分离
摘自 开源项目Ibase4j 关键思想在于AbstractRoutingSource 类 还有方法名称和切入点去控制使用哪个数据源 1.首先在配置文件配置多个数据源 并且交给继承自spri ...
- python打造XslGenerator
0x00前言 今天加载了Demon哥分享的RSS.其中有一篇是三好学生讲的: 在仔细越读这篇文章后,我懂得了里面的一些骚操作,所以有了以下的 脚本. 0x001代码 import optparse i ...
- Java知识总结----队列的使用
首先我们要知道使用队列的目的是什么?一般情况下,如果是一些及时消息的处理,并且处理时间很短的情况下是不需要使用队列的,直接阻塞式的方法调用就可以了.但是,如果在消息处理的时候特别费时间,这个时候如果有 ...
- Java核心知识点 --- 线程中如何创建锁和使用锁 Lock , 设计一个缓存系统
理论知识很枯燥,但这些都是基本功,学完可能会忘,但等用的时候,会发觉之前的学习是非常有意义的,学习线程就是这样子的. 1.如何创建锁? Lock lock = new ReentrantLock(); ...
- minio test
docker pull minio/minio docker run --name=minio -d -p 9001:9000 minio/minio server /data https://do ...
- python's metaclass
[python's metaclass] 和objc中类似,metaclass用于创建一个类对象,但与objc不同的是,objc中每个类对象有各自不同的metaclass,而python中的metac ...