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 ...
随机推荐
- h5调用手机摄像头/相册
<!DOCTYPE HTML><html><head> <title>上传图片</title> <meta charset=" ...
- java web 程序--注册页面/HashMap的用法。。要懂啊
思路:1.一个form表单,用户输入后,提交 2.第二个是注册页面,主要是用Map.先假设往map里面拿东西,然后判断是否为空 若为空,new 一个HashMap它的子类,然后通过map.conta ...
- python的数据类型,数字,布尔,字符串
1.数字 数字过大,类型会自动变化,这个变化是python2特有的,在python3里都是int,不区分int和long float(浮点型),也就是小数 complex(复数) 2.布尔值 真或者假 ...
- 虚拟机桥接网卡下配置centOS静态IP
前面我们讲了怎么去配置asterisk,但是配置完了,是没有什么效果出现的,因为asterisk相当于一个服务器,我们需要一个客户端去给它连接起来,如果你是在自己的机子上装了虚拟机,那最好配一下cen ...
- python mac下使用多进程报错解决办法
使用pychram运行python web,web使用了多进程 mac下运行会提示如下: may have been in progress in another thread when fork() ...
- SharePoint 事件 2137 / 2138 :SharePoint 运行状况分析器检测到错误。驱动器的可用空间不足。
转自MSDN:http://technet.microsoft.com/zh-cn/library/ff805057.aspx 摘要:服务器场中的一个或多个服务器上的磁盘驱动器的可用空间不足. 注意: ...
- linux weather
- maven-resources-plugin使用
命令行中带参数指定${}变量值 <build> <resources> <resource> <directory>src/main/resources ...
- ATL接口返回类型&&ATL接口返回字符串BSTR*
感觉在ATL中做COM组件,添加方法的时候,其返回值只能是HRESULT,我想返回其他数据类型,可以吗? 非也非也 HRESULT指示返回的状态,即正确与否, 返回值是这样的 HRESULT MyMe ...
- linux 常用查看设备命令(转)
# uname -a # 查看内核/操作系统/CPU信息 # /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # 查看CPU信息 # hostname # 查看计算 ...