poj 1028 Web Navigation 【模拟题】
题目地址:http://poj.org/problem?id=1028
测试样例:
Sample Input
VISIT http://acm.ashland.edu/
VISIT http://acm.baylor.edu/acmicpc/
BACK
BACK
BACK
FORWARD
VISIT http://www.ibm.com/
BACK
BACK
FORWARD
FORWARD
FORWARD
QUIT
Sample Output
http://acm.ashland.edu/
http://acm.baylor.edu/acmicpc/
http://acm.ashland.edu/
http://www.acm.org/
Ignored
http://acm.ashland.edu/
http://www.ibm.com/
http://acm.ashland.edu/
http://www.acm.org/
http://acm.ashland.edu/
http://www.ibm.com/
Ignored 题目分析:
指令操作:
需要支持如下命令:
BACK:把当前页面放入“前进栈”的最顶部,并从“后退栈”中取出顶部元素,使其为当前浏览页面。如果“后退栈”为空,则忽略当前操作。
FORWARD:把当前页面放入“后退栈”的最顶部,并从“前进栈”中取出顶部元素,使其为当前浏览页面。如果“前进栈”为空,则忽略当前操作。
VISIT :将当前页面放入后退栈的顶部,并设置URL为当前指定页面。前进栈设置为空。
QUIT:退出浏览器。
假设浏览器初始登入URL网页:http://www.acm.org/
注意:当你BACK 或者 FORWARD 的时候,如果要转换的页面不存在,需要输出Ignored 的时候,不要把当前的页面加入 前进栈 或者 后退栈。
除非要转换的页面存在,才将当前的页面 加入前进栈或者后退栈。
代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <queue>
#include <iostream>
#include <string>
#include <algorithm> using namespace std; int main()
{
stack<string>s_back; //后退栈
stack<string>s_forw; //前进栈 //假设浏览器初始登入URL网页:http://www.acm.org/
string instruct; //操作指令
string cur="http://www.acm.org/";//当前开始页面
string temp; while(cin>>instruct )
{
if(instruct=="QUIT") break;
if(instruct=="VISIT") //执行此指令后要将当前页面加入后退栈
{ //遇到访问新的页面 //并且前进栈要清空
cin>>temp;
s_back.push(cur); //加入后退栈
cur=temp;
cout<<cur<<endl;
while(!s_forw.empty()) s_forw.pop();
}
if(instruct=="BACK")
{
if(!s_back.empty()){
s_forw.push(cur);//将当前页面加入前进栈 注意:要包含在if语句内 否则会错
cur=s_back.top(); s_back.pop();//不要忘记出栈
cout<<cur<<endl;
}
else printf("Ignored\n");
}
if(instruct=="FORWARD")
{
if(!s_forw.empty()){
s_back.push(cur); // 注意:要包含在if语句内 否则会错
cur=s_forw.top(); s_forw.pop();
cout<<cur<<endl;
}
else printf("Ignored\n");
}
}
return 0;
}
poj 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 题解
考查代码能力的题目.也能够说是算法水题,呵呵. 推荐新手练习代码能力. 要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈.做多了,我就直接使用STL了. #includ ...
- poj 1888 Crossword Answers 模拟题
Crossword Answers Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 869 Accepted: 405 D ...
- POJ - 1835 宇航员(模拟题)
问题描述: 宇航员在太空中迷失了方向,在他的起始位置现在建立一个虚拟xyz坐标系,称为绝对坐标系,宇航员正面的方向为x轴正方向,头顶方向为z轴正方向,则宇航员的初始状态如下图所示: 现对六个方向分别标 ...
- 1028 Web Navigation
题目链接: http://poj.org/problem?id=1028 题意: 模拟浏览器的前进/后退/访问/退出 的四个操作. 输出当前访问的URL或者Ignore(如果不能前进/后退). 分析: ...
- poj 1208 Web Navigation(堆栈操作)
一.Description Standard web browsers contain features to move backward and forward among the pages re ...
- POJ 2348 Euclid Game (模拟题)
Euclid's Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7942 Accepted: 3227 Des ...
- POJ 1028:Web Navigation
Web Navigation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30828 Accepted: 13821 ...
随机推荐
- $.ajax 温故而知新坑
$.ajax的配置项中使用 contentType: "application/json" 时,Data选项允许为String类型,如JSON.stringify({abc:123 ...
- php里面用魔术方法和匿名函数闭包函数动态的给类里面添加方法
1.认识 __set (在给不可访问属性赋值时,__set() 会被调用) 也就是说你再访问一个类里面没有的属性,会出发这个方法 class A{ private $aa = '11'; publ ...
- scala 编写wordCount
加载文件 scala> var f1=sc.textFile("/tmp/dataTest/followers.txt") scala> f1.flatMap(x=&g ...
- TCP粘包处理通用框架--C代码
说明:该文紧接上篇博文“ linux epoll机制对TCP 客户端和服务端的监听C代码通用框架实现 ”讲来 (1)TCP粘包处理数据结构设计 #define MAX_MSG_LEN 65535 ty ...
- ubuntu中文乱码--添加中文字符集
在Ubuntu支持中文后(方法见上篇文章),默认是UTF-8编码,而Windows中文版默认是GBK编码.为了一致性,通常要把Ubuntu的默认 编码改为GBK.当然你也可以不改,但这会导致我们在两个 ...
- 九度OJ 1199:找位置 (计数)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2083 解决:1010 题目描述: 对给定的一个字符串,找出有重复的字符,并给出其位置,如:abcaaAB12ab12 输出:a,1:a,4 ...
- SQLServer判断一个IP是否在一个IP段里
declare @ip1 varchar(20)declare @ip2 varchar(20)set @ip1='221.231.138.101'set @ip2='255.255.255.255' ...
- liferay 指定默认首页
1.登录liferay后,点击控制面板-->设置--> portal设置 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZmVuZ3hpbmdf ...
- 016-Spring Boot JDBC
一.数据源装配 通过查看代码可知,默认已装配了数据源和JdbcTemplate System.out.println(context.getBean(DataSource.class)); Syste ...
- [转载]Java集合容器简介
Java集合容器主要有以下几类: 1,内置容器:数组 2,list容器:Vetor,Stack,ArrayList,LinkedList, CopyOnWriteArrayList(1.5),Attr ...