poj 1028 Web Navigation(模拟)
id=1028
Description
are asked to implement this.
The following commands need to be supported:
BACK: Push the current page on the top of the forward stack. Pop the page from the top of the backward stack, making it the new current page. If the backward stack is empty, the command is ignored.
FORWARD: Push the current page on the top of the backward stack. Pop the page from the top of the forward stack, making it the new current page. If the forward stack is empty, the command is ignored.
VISIT : Push the current page on the top of the backward stack, and make the URL specified the new current page. The forward stack is emptied.
QUIT: Quit the browser.
Assume that the browser initially loads the web page at the URL http://www.acm.org/
Input
The end of input is indicated by the QUIT command.
Output
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
Source
题意:
模拟浏览器浏览网页是前后翻页。
思路:
开两个栈。分别存储当前网页前后的网页,注意新訪问一个网页时,应该把当前网页的前面的栈清空!
代码例如以下:
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
stack <string>b;
stack <string>f;
int main()
{
string tt = "http://www.acm.org/";
string s;
while(cin >> s)
{
if(s == "QUIT")
break;
if(s == "VISIT")
{
b.push(tt);
cin >> tt;
cout<<tt<<endl;//始终输出当前页
while(!f.empty())//当新訪问一个页面的时候把之前页面前面的清空
{
f.pop();
}
}
else if(s == "BACK")
{
if(!b.empty())
{
f.push(tt);
tt = b.top();
b.pop();
cout<<tt<<endl;//始终输出当前页
}
else
cout<<"Ignored"<<endl;
}
else
{
if(!f.empty())
{
b.push(tt);
tt = f.top();
f.pop();
cout<<tt<<endl;//始终输出当前页
}
else
cout<<"Ignored"<<endl;
}
}
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 测试样例: Sample Input VISIT http://acm.ashland.edu/ VISIT http://ac ...
- POJ 1028 Web Navigation 题解
考查代码能力的题目.也能够说是算法水题,呵呵. 推荐新手练习代码能力. 要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈.做多了,我就直接使用STL了. #includ ...
- 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 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实现. ...
- 【stack】模拟网页浏览 poj 1028
#include<stdio.h> #include<string.h> int main() { ][]; ]; int i,depth; strcpy(s[]," ...
- 使用 Web API 模拟其他用户
模拟的要求 模拟可代表另一个 Microsoft Dynamics CRM 用户,用于执行业务逻辑(代码)以便提供所需功能或服务,它使用模拟用户的相应角色和基于对象的安全性.这项技术很有必要,因为 M ...
随机推荐
- 使用django发送邮件时的连接超时问题解决
一.报错 研究报错半天,没看出代码有什么毛病,就是发送邮件时连接超时,发送邮件的连接用户名密码都没有错误,于是就网上各种查... 终于皇天不负有心人,找到答案了.. 在服务器上输入telnet smt ...
- GrideVlew提供点击按钮添加新数据,单击项目修改,长按删除功能
package com.example.wang.myapplication; import android.app.AlertDialog; import android.content.Dialo ...
- 使用mongo-java-driver-3.0.2连接MongoDB数据库
这里使用的mongodb的java驱动版本是:3.0.2,文件名mongo-java-driver-3.0.2.jar 博客本地下载下载网址(也可以下载其它版本):http://central.ma ...
- python开发学习-day14(jquery、ajax等)
s12-20160421-day14 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...
- Keras中RNN不定长输入的处理--padding and masking
在使用RNN based model处理序列的应用中,如果使用并行运算batch sample,我们几乎一定会遇到变长序列的问题. 通常解决变长的方法主要是将过长的序列截断,将过短序列用0补齐到一个固 ...
- 【LOJ】#2064. 「HAOI2016」找相同字符
题解 做后缀自动机题要一点脑洞,脑洞一开,就过了 我们显然要拿第二个串跑第一个串的后缀自动机 我们可以求出第二个串每个位置匹配到的节点,和匹配的长度L 那么我们统计一个后缀树上的根缀和,表示这样个节点 ...
- 浅谈jvm
1 .说起jvm,很多人感觉jvm离我们开发实际很远.但是,我们开发缺每时每刻都离不开jvm. a: java源码 编译后成.class字节码文件, b:根据classpath找到这个字节码文件, c ...
- ESLint处理
当有遇到下划线的问题,会提示有问题,无法通过检测 需要在代码的前面加入以下代码就可以解决,地址是:https://stackoverflow.com/questions/44126983/eslint ...
- CentOS 5.x上配置JBoss6.x步骤图解教程
1.如何远程连接CentOS和文件上传下载 使用工具Xmanager下的Xbroswer 首先在Xbroswer下的Xshell下新建文件夹JavaPlatServer,新建一个Xshell Sess ...
- [leetcode sort]57. Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...