poj 1028 Web Navigation
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 31088 | Accepted: 13933 |
Description
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
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
//http://poj.org/problem?id=1028
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <iostream>
using namespace std;
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
stack<string> f,b;
int num=;
string curs="http://www.acm.org/",news;
//cin>>s&&s!="QUIT"
while(cin>>news&&news!="QUIT"){
//cout<<num++<<" "<<news<<" ";
if(news=="BACK"){
if(!b.empty()){
f.push(curs);
curs=b.top();
b.pop();
cout<<curs<<endl;
}
else{
printf("Ignored\n");
}
}
else{
if(news=="FORWARD"){
if(!f.empty()){
b.push(curs);
curs=f.top();
f.pop();
cout<<curs<<endl;
}
else{
printf("Ignored\n");
}
}
else{
b.push(curs);
cin>>curs;
while(!f.empty()){
f.pop();
}
cout<<curs<<endl;
}
}
}
return ;
}
poj 1028 Web Navigation的更多相关文章
- 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 ...
- 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实现. ...
- poj 1028
http://poj.org/problem?id=1028 题意(水):做一个游览器的历史记录. back:后退到上一个页面,当上一个页面没有时,输出ignored. forward:向前一个页面, ...
- 【POJ 1984】Navigation Nightmare(带权并查集)
Navigation Nightmare Description Farmer John's pastoral neighborhood has N farms (2 <= N <= 40 ...
随机推荐
- ecliplse里tomcat正常启动后http://localhost:8080/报错404
如下图所示,新建一个工作区间,添加tomcat之后通过ecliplse启动tomcat之后: 访问http://localhost:8080/出现404: 解决方法: 1.确保tomcat里面所有项目 ...
- 在Linux环境下的卸载Oracle11G操作
1.使用SQL*PLUS停止数据库[oracle@OracleTest oracle]$ sqlplus /nolog SQL> connect / as sysdba SQL> shut ...
- jquery $.each()循环退出
$.each()循环跳出,应该用return 来返回 在each代码块内不能使用break和continue,要实现break和continue的功能的话,要使用其它的方式:break----用ret ...
- 跳转iPhone设置页面,绕过审核
1.问题描述 跳转iPhone设置页面之前都是通过 App-Prefs:root=WIFI 来跳转,但是2018年6月废弃了这个函数,被认为是私有函数,审核会被拒绝. 有心人采用了字符串转码的方式来规 ...
- cookie,session 的概念以及在django中的用法,以及cbv装饰器用法
cookie的由来: 大家都知道HTTP协议是无状态的. 无状态的意思是每次请求都是独立的,它的执行情况和结果与前面的请求和之后的请求都无直接关系,它不会受前面的请求响应情况直接影响,也不会直接影响后 ...
- P1129 [ZJOI2007]矩阵游戏(二分图,网络流)
传送门 这推导过程真的有点可怕的说……完全想不出来…… 最终状态是$(1,1),(2,2),(3,3)...(n,n)$都有一个黑点 我们可以理解为每一个行和列都形成了一个匹配 换句话说,只要$n$行 ...
- 使用C语言封装数组,动态实现增删改查
myArray.h : #pragma once //包含的时候只包含一次 #include <stdio.h> #include <stdlib.h> #include &l ...
- jwt-dotnet使用示例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- IOS中NSUserDefaults的用法
NSUserDefaults适合存储轻量级本地数据,比如要保存用户登陆的用户名.密码,使用NSUserDefaults是首选.下次再登陆的时候就可以直接从NSUserDefaults里面读取上次登陆的 ...
- winform工具1-图片去除水印
效果图: 思路: 1.获取图片 2.处理水印 3.保存处理的图片 代码: 获取图片: private void button1_Click(object sender, EventArgs e) { ...