题目链接: 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的更多相关文章

  1. poj 1028 Web Navigation

    Web Navigation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31088   Accepted: 13933 ...

  2. poj 1028 Web Navigation(模拟)

    题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...

  3. poj 1028 Web Navigation 【模拟题】

    题目地址:http://poj.org/problem?id=1028 测试样例: Sample Input VISIT http://acm.ashland.edu/ VISIT http://ac ...

  4. POJ 1028 Web Navigation 题解

    考查代码能力的题目.也能够说是算法水题,呵呵. 推荐新手练习代码能力. 要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈.做多了,我就直接使用STL了. #includ ...

  5. POJ 1028:Web Navigation

    Web Navigation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30828   Accepted: 13821 ...

  6. POJ1028 Web Navigation

    题目来源:http://poj.org/problem?id=1028 题目大意: 模拟实现一个浏览器的“前进”和“回退”功能.由一个forward stack和一个backward stack实现. ...

  7. POJ-1028 Web Navigation 和TOJ 1196. Web Navigation

    Standard web browsers contain features to move backward and forward among the pages recently visited ...

  8. Web Navigation

    Description Standard web browsers contain features to move backward and forward among the pages rece ...

  9. [POJ1028]Web Navigation(栈)

    这题是01年East Central North的A题,目测是签到题 Description Standard web browsers contain features to move backwa ...

随机推荐

  1. zabbix3.44+交换机华为或者H3C模版,监控所有的口updown以及流量的模版

    https://files.cnblogs.com/files/itfat/zbx_export_templates.xml 直接在zabbix导入即可,华为和H3C oid在CPU和内存有少许区别. ...

  2. ALSA声卡10_从零编写之数据传输_学习笔记

    1.引言 (1)应用程序使用声卡的时候,数据流程是:应用程序把数据发送给驱动,驱动把数据发送给硬件声卡,声卡把数据转换成声音数据播放出去. (2)可以使用两种方式发送数据 第一种:app发数据,等驱动 ...

  3. 5月9日上课笔记-网页定位、网页动画【HTML5】

    一.网页定位 position: static (默认值) relative 相对定位(相对原来的位置) right left botton top absolute 绝对定位 fixed: 固定定位 ...

  4. C语言学习笔记---好用的函数memcpy与memset

    这个主要用于我个人的学习笔记,便于以后查询,顺便分享给大家. 想必在用C的时候难免会与数组,指针,内存这几样东西打交道,先以数组为例,例如有一个数组int a[5] = {1, 2, 3, 4, 5} ...

  5. 08_java超市管理系统

    超市管理系统功能介绍 * A:超市管理系统功能介绍 * a: 显示主菜单 ============欢迎光临ItCast超市============ 1: 货物 清单 2: 添加货物 3: 删除货物 4 ...

  6. django之上传图片

    上传图片 当Django在处理文件上传的时候,文件数据被保存在request.FILES FILES中的每个键为<input type="file" name="& ...

  7. 流程管理软件(BPM)功能简介

    易协流程管理系统实现将人为控制的业务活动,通过信息化手段实现系统控制,降低人为控制管理的风险以及促进企业的各项决策方针的顺利实施. 系统目标: 实现管理的规范化.制度化.程序化: 帮助企业将内控制度流 ...

  8. 重写iframe内联框架中的内容

    重写iframe内联框架中的内容,不使用src指向页面url,主动写入HTML代码: var ifr = document.getElementById("CMBC-certificatio ...

  9. Variant

    class RTL_DELPHIRETURN Variant: public TVarData Variant转换为字符串 System::Variants::VarToStr VariantArra ...

  10. 拼接两个yuv合帧

    http://blog.csdn.net/huahuahailang/article/details/9040847 /**************************************** ...