这题是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. Delphi获取其它进程窗口句柄的3种方法

    本文主要跟大家介绍Delphi中获取其它进程的窗口句柄,在Delphi中获取其它进程的窗口句柄,绝大部分人首先想到的会使用:FindWindow或者用GetWindow来遍历查找,如: handle ...

  2. bootstrap 基础表单 内联表单 横向表单

    bootstrap 基础表单 内联表单 横向表单 <!DOCTYPE html> <html> <head> <title></title> ...

  3. Servlet RequestDispatcher需要注意的情况

    Servlet RequestDispatcher需要注意的情况: 如果使用getServletContext().getRequestDispatcher("/a.do")得到R ...

  4. 创建 OVS vlan101 并部署 instance - 每天5分钟玩转 OpenStack(139)

    前面我们创建了 OVS vlan100 并部署了 instance,今天继续创建 vlan101. subnet IP 地址为 172.16.101.0/24. 底层网络发生了什么变化 Neutron ...

  5. JS-鼠标滚轮事件 和 阻止默认行为

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  6. HDU1175(dfs)

    连连看 Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description ...

  7. 使用数字签名实现数据库记录防篡改(Java实现)

    本文大纲 一.提出问题 二.数字签名 三.实现步骤 四.参考代码 五.后记 六.参考资料 一.提出问题 最近在做一个项目,需要对一个现成的产品的数据库进行操作,增加额外的功能.为此,需要对该产品对数据 ...

  8. requireJS的初步掌握(二)

    前面我们讲述了requireJS的一些认知和优点,==>http://www.cnblogs.com/wymbk/p/6366113.html 这章我们主要描述的是requireJS的一些常用的 ...

  9. JavaSE 教程的选择

    你好 我是大福 你现在看的是大福笔记 又降温了 下点小雨 出门有点冷 走路到公司20多分钟,又走的有点热 昨天说到了,今年的计划是从零开始重新学习并梳理下这两年学习和接触到的技术 那么今天开始第一个知 ...

  10. std::vector 源代码

    vector身为一个动态数组,每次以空间不够的时候会以2倍的倍数增加,而且每次扩充的时候分为3部,分配内存,拷贝数据,释放内存 vector内部有两个成员变量,begin,finish ,endcat ...