这题是01年East Central North的A题,目测是签到题

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

 
题目描述的已经很清楚了,很明确的就是使用栈来实现类似浏览器前进后退的功能吧。
(很适合初学栈的新手哦~)
 
上代码了:
 
import java.util.Scanner;
import java.util.Stack; public class Main { public static String visited = "VISIT";
public static String back = "BACK";
public static String forward = "FORWARD";
public static String quit = "QUIT"; public static void main(String[] args) {
Stack<String> bStack = new Stack<String>();
Stack<String> fStack = new Stack<String>();
String preUrl = "http://www.acm.org/";
bStack.push(preUrl);
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String command = sc.next();
if (command.equals(visited)) {
String url = sc.next();
System.out.println(url);
bStack.push(url);
fStack.clear();
} else if (command.equals(back)) {
if(bStack.size() > 1){
String url = bStack.pop();
System.out.println(bStack.peek());
fStack.push(url);
}else{
System.out.println("Ignored");
}
} else if (command.equals(forward)) {
if(fStack.size() > 0){
String url = fStack.pop();
System.out.println(url);
bStack.push(url);
}else{
System.out.println("Ignored");
}
}else if(command.equals("QUIT")){
break;
}
}
}
}
 
 

[POJ1028]Web Navigation(栈)的更多相关文章

  1. POJ1028 Web Navigation

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

  2. POJ-1028 Web Navigation 和TOJ 1196. Web Navigation

    Standard web browsers contain features to move backward and forward among the pages recently visited ...

  3. 《web全栈工程师的自我修养》读书笔记

    有幸读了yuguo<web全栈工程师的自我修养>,颇有收获,故在此对读到的内容加以整理,方便指导,同时再回顾一遍书中的内容. 概览 整本书叙述的是作者的成长经历,通过经验的分享,给新人或者 ...

  4. 基于LeanCloud云引擎的Web全栈方案

    LeanEngine-Full-Stack The FULL STACK DEVELOPER 复杂的项目, 协作分工, 自动化流程,代码组织结构,框架选择,国际化方案等 Generator 或者See ...

  5. 《web全栈工程师的自我修养》阅读笔记

    在买之前以为这本书是教你怎么去做一个web全栈工程师,以及介绍需要掌握的哪些技术的书,然而看的过程中才发现,是一本方法论的书.读起来的感觉有点像红衣教主的<我的互联网方法论>,以一些自己的 ...

  6. web性能优化 来自《web全栈工程师的自我修养》

    最近在看<web全栈工程师的自我修养>一书,作者是来自腾讯的前端工程师.作者在做招聘前端的时候问应聘者web新能优化有什么了解和经验,应聘者思索后回答“在发布项目之前压缩css和 Java ...

  7. 处女作《Web全栈开发进阶之路》出版了!

    书中源码下载地址:https://github.com/qinggee/WebAdvanced 01. 当初决定写博客的原因非常的纯洁:只要每个月写上 4 篇以上博客,月底的绩效奖金就多 500 块. ...

  8. web技术栈中不可或缺的Linux技术

    Web技术最重要的载体便是服务器,服务器运行在公共的网络环境下,为广大的用户提供网页浏览.信息通讯.消息推送等服务,从最开始的硬件服务器到虚拟主机技术,再到虚拟化技术的出现和云概念的兴起,绝大部分都是 ...

  9. poj 1028 Web Navigation

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

随机推荐

  1. A窗口消失B窗口弹出

    一.设计窗口 1) file---new--Application,新建一个窗体,设置该窗体的属性:Caption==登录窗口 2) procedure TForm1.btn1Click(Sender ...

  2. IIS8中添加WCF支持几种方法小结[图文]

    方法一 最近在做Silverlight,Windows Phone应用移植到Windows 8平台,在IIS8中测试一些传统WCF服务应用,发现IIS8不支持WCF服务svc请求,后来发现IIS8缺少 ...

  3. HTML 颜色名

    目前所有浏览器都支持以下颜色名. 141个颜色名称是在HTML和CSS颜色规范定义的(17标准颜色,再加124).下表列出了所有颜色的值,包括十六进制值.  提示: 17标准颜色:黑色,蓝色,水,紫红 ...

  4. 排名前10的H5、Js 3D游戏引擎和框架

    由于很多人都在用JavaScript.HTML5和WebGL技术创建基于浏览器的3D游戏,所有JavaScript 3D游戏引擎是一个人们主题.基于浏览器的游戏最棒的地方是平台独立,它们能在iOS.A ...

  5. Boost.Asio技术文档

    Christopher Kohlhoff Copyright © 2003-2012 Christopher M. Kohlhoff 以Boost1.0的软件授权进行发布(见附带的LICENSE_1_ ...

  6. Chrome中java因过期而遭到阻止

    http://www.cnblogs.com/jifeng/p/3453322.html 在Chrome快捷方式图标上右击,选[属性],然后在[目标]一栏的末尾添加这么一段命令(flag): --al ...

  7. 【.net 深呼吸】细说CodeDom(10):生成异常处理语句

    写完这一篇,大概可以准备过年了,就算是这系列文章的收尾吧. 异常处理语句,就是常说的try...catch语句,有时候,也会带有finally子句.要生成异常处理语句,得用到CodeTryCatchF ...

  8. delphi 预览图片2 (MouseUP)

    这个是自己项目在使用的,所以带有些业务功能的代码. 逻辑上使用的大多是 mouseup ,MouseMove,Mousedown.使用recttangle容器实现滑动.网上有这个下载demo. 另外移 ...

  9. loadrunner:参数类型及其取值机制

    参数类型 参数名随意取,建议取通俗易懂的名字,下面我们重点介绍一下参数的类型. ●DateTime: 很简单, 在需要输入日期/时间的地方, 可以用DateTime 类型来替代. 其属性设置也很简单, ...

  10. 关于Task的一点思考和建议

    前言 本打算继续写SQL Server系列,接下来应该是死锁了,但是在.NET Core项目中到处都是异步,最近在写一个爬虫用到异步,之前不是很频繁用到异步,当用到时就有点缩手缩尾,怕留下坑,还是小心 ...