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 ...
随机推荐
- Java 打印一个心心
package Day8_06; public class For { public static void main(String[] args) { System.out.println(&quo ...
- nginx限制请求之二:(ngx_http_limit_req_module)模块
相关文章: <高可用服务设计之二:Rate limiting 限流与降级> <nginx限制请求之一:(ngx_http_limit_conn_module)模块> <n ...
- NGUI的UICamera
参考 https://blog.csdn.net/kakashi8841/article/details/20548429 全文请查看:http://note.youdao.com/notesha ...
- Linux 发展史
操作系统 英文名称为operating system,简称os,是应用程序运行及用户操作必备的基础环境支撑,计算机系统的核心,作用是管理和控制计算机系统中的硬件和软件资源 操作系统就是处于用户与计算机 ...
- 用CSS绘制最常见的40种形状和图形
今天在国外的网站上看到了很多看似简单却又非常强大的纯CSS绘制的图形,里面有最简单的矩形.圆形和三角形,也有各种常见的多边形,甚至是阴阳太极和网站小图标,真的非常强大,分享给大家. Square(正方 ...
- 4_python之路之模拟工资管理系统
python之路之模拟工资管理系统 1.程序说明:Readme.txt 1.程序文件:salary_management.py info.txt 2.程序文件说明:salary_management. ...
- C和指针 第三章--数据
简要概述: <C和指针>第三章对数据进行了描述. 其中主要讲解了---变量的三个属性:作用域.链接属性和存储类型. 这三个属性决定了该变量在“什么地方可以使用”以及“该变量的值能够保持多久 ...
- *(ptr++) += 123
*(ptr++) += 123; 等价于:*(ptr) = *(ptr) + 123; ptr++; 而不是:*(ptr++) = *(ptr++) + 123;程序员面试宝典p32 #include ...
- Fastq 常用软件
文章转载于 Original 2017-06-08 Jolvii 生信百科 由于生物信息的大部分工作都是在没有 root 权限的集群上进行的,本期我主要介绍一下非 root 用户怎么安装常用的软件.工 ...
- spring+mybatis之注解式事务管理初识(小实例)
1.上一章,我们谈到了spring+mybatis声明式事务管理,我们在文章末尾提到,在实际项目中,用得更多的是注解式事务管理,这一章将学习一下注解式事务管理的有关知识.注解式事务管理只需要在上一节的 ...