Web Navigation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 31088   Accepted: 13933

Description

Standard web browsers contain features to move backward and forward among the pages recently visited. One way to implement these features is to use two stacks to keep track of the pages that can be reached by moving backward and forward. In this problem, you 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

Input is a sequence of commands. The command keywords BACK, FORWARD, VISIT, and QUIT are all in uppercase. URLs have no whitespace and have at most 70 characters. You may assume that no problem instance requires more than 100 elements in each stack at any time. The end of input is indicated by the QUIT command.

Output

For each command other than QUIT, print the URL of the current page after the command is executed if the command is not ignored. Otherwise, print "Ignored". The output for each command should be printed on its own line. No output is produced for the QUIT command.

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的更多相关文章

  1. poj 1028 Web Navigation(模拟)

    题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...

  2. poj 1028 Web Navigation 【模拟题】

    题目地址:http://poj.org/problem?id=1028 测试样例: Sample Input VISIT http://acm.ashland.edu/ VISIT http://ac ...

  3. POJ 1028 Web Navigation 题解

    考查代码能力的题目.也能够说是算法水题,呵呵. 推荐新手练习代码能力. 要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈.做多了,我就直接使用STL了. #includ ...

  4. 1028 Web Navigation

    题目链接: http://poj.org/problem?id=1028 题意: 模拟浏览器的前进/后退/访问/退出 的四个操作. 输出当前访问的URL或者Ignore(如果不能前进/后退). 分析: ...

  5. poj 1208 Web Navigation(堆栈操作)

    一.Description Standard web browsers contain features to move backward and forward among the pages re ...

  6. POJ 1028:Web Navigation

    Web Navigation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30828   Accepted: 13821 ...

  7. POJ1028 Web Navigation

    题目来源:http://poj.org/problem?id=1028 题目大意: 模拟实现一个浏览器的“前进”和“回退”功能.由一个forward stack和一个backward stack实现. ...

  8. poj 1028

    http://poj.org/problem?id=1028 题意(水):做一个游览器的历史记录. back:后退到上一个页面,当上一个页面没有时,输出ignored. forward:向前一个页面, ...

  9. 【POJ 1984】Navigation Nightmare(带权并查集)

    Navigation Nightmare Description Farmer John's pastoral neighborhood has N farms (2 <= N <= 40 ...

随机推荐

  1. 死磕Java之聊聊HashSet源码(基于JDK1.8)

    HashSet的UML图 HashSet的成员变量及其含义 public class HashSet<E> extends AbstractSet<E> implements ...

  2. hive默认分隔符

    默认分隔符‘\001',对应ascii码SOH: 通过cat -A filename可以查看分隔符:

  3. javascript正则表达式——元字符

    元字符(Metacharacter)是拥有特殊含义的字符: 元字符        描述 (1)   .             查找单个字符,除了换行和行结束符. 例子: <!DOCTYPE h ...

  4. 为什么不应该重写service方法?

      故事通常是这样开始的: 从前,有一个程序猿,他语重心长地对孙子说:“孩子,要是你以后写servlet,最好不要重写service方法啊” 孙子大为不解,程序猿又说:“听爷爷的,准没错,爷爷的爷爷就 ...

  5. [SinGuLaRiTy] 树链问题

    [SinGuLaRiTy-1035] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 关于树链 树链是什么?这个乍一看似乎很陌生的词汇表达的其 ...

  6. MongoDB 深入学习 -- ReplSet,Sharding,Security,Aggregation,Command

    萌新最近在对付MongoDB,因此每天都在翻官方文档,这里随便做点笔记 ReplSet 与 Sharding ReplSet 是副本集,也就是主从集合.可以用来做负载均衡,数据热备份.副本集的配置相对 ...

  7. 51nod1832(二叉树/高精度模板+dfs)

    题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1832 题意: 中文题诶~ 思路: 若二叉树中有 k 个节点只 ...

  8. php中的静态方法实例理解

    <?php header("content-type:text/html;charset=utf-8"); class Human{ static public $name ...

  9. Rebranding(模拟+思维)

    The name of one small but proud corporation consists of n lowercase English letters. The Corporation ...

  10. 蓝桥-青蛙跳杯子(bfs)

    问题描述 X星球的流行宠物是青蛙,一般有两种颜色:白色和黑色. X星球的居民喜欢把它们放在一排茶杯里,这样可以观察它们跳来跳去. 如下图,有一排杯子,左边的一个是空着的,右边的杯子,每个里边有一只青蛙 ...