这题是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

  1. VISIT http://acm.ashland.edu/
  2. VISIT http://acm.baylor.edu/acmicpc/
  3. BACK
  4. BACK
  5. BACK
  6. FORWARD
  7. VISIT http://www.ibm.com/
  8. BACK
  9. BACK
  10. FORWARD
  11. FORWARD
  12. FORWARD
  13. QUIT

Sample Output

  1. http://acm.ashland.edu/
  2. http://acm.baylor.edu/acmicpc/
  3. http://acm.ashland.edu/
  4. http://www.acm.org/
  5. Ignored
  6. http://acm.ashland.edu/
  7. http://www.ibm.com/
  8. http://acm.ashland.edu/
  9. http://www.acm.org/
  10. http://acm.ashland.edu/
  11. http://www.ibm.com/
  12. Ignored

Source

 
题目描述的已经很清楚了,很明确的就是使用栈来实现类似浏览器前进后退的功能吧。
(很适合初学栈的新手哦~)
 
上代码了:
 
  1. import java.util.Scanner;
  2. import java.util.Stack;
  3.  
  4. public class Main {
  5.  
  6. public static String visited = "VISIT";
  7. public static String back = "BACK";
  8. public static String forward = "FORWARD";
  9. public static String quit = "QUIT";
  10.  
  11. public static void main(String[] args) {
  12. Stack<String> bStack = new Stack<String>();
  13. Stack<String> fStack = new Stack<String>();
  14. String preUrl = "http://www.acm.org/";
  15. bStack.push(preUrl);
  16. Scanner sc = new Scanner(System.in);
  17. while (sc.hasNext()) {
  18. String command = sc.next();
  19. if (command.equals(visited)) {
  20. String url = sc.next();
  21. System.out.println(url);
  22. bStack.push(url);
  23. fStack.clear();
  24. } else if (command.equals(back)) {
  25. if(bStack.size() > 1){
  26. String url = bStack.pop();
  27. System.out.println(bStack.peek());
  28. fStack.push(url);
  29. }else{
  30. System.out.println("Ignored");
  31. }
  32. } else if (command.equals(forward)) {
  33. if(fStack.size() > 0){
  34. String url = fStack.pop();
  35. System.out.println(url);
  36. bStack.push(url);
  37. }else{
  38. System.out.println("Ignored");
  39. }
  40. }else if(command.equals("QUIT")){
  41. break;
  42. }
  43. }
  44. }
  45. }
 
 

[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. main函数执行前、后再执行的代码

    一.main结束 不代表整个进程结束  (1)全局对象的构造函数会在main 函数之前执行,          全局对象的析构函数会在main函数之后执行:          用atexit注册的函数 ...

  2. win7配置自己的IIS服务器亲自做的图文很详细

    跟人网站爱好初学者必看的win7系统配置自己的IIS,可以在你自己的电脑上配置网站服务器发不到网上,下面就跟着我的步骤一起做吧100%成功. 步骤/方法     点击开始-------控制面板这个就是 ...

  3. doubango(1)--从协议栈结构说起

    自顶向下与自底向上 软件设计的两种方法不过于自顶向下与自底向上. 对于自顶向下而言,先设计好用户接口,再往下延伸至各个功能块的具体实现.而对于自底向上而言,自然是有了设计好的各个功能代码块,再将这些功 ...

  4. 在Windows下开发Node.js的C/C++原生扩展

    准备工作 (1)本机系统说明:本人机器为win7 64位,32位也可以. (2)软件安装: VISUAL C++ 2010 EXPRESS(Visual Studio 2010也可以): window ...

  5. 005.数组、for、foreach

    1.方法的传输传递 值参数:传递的是副本 引用参数:自身 保留自定义的方法中对值的改变 形参影响实参ref:对应的形参和实参都用ref修饰 输出参数:实参不用赋值,但是自定义方法内必须对此参数赋值!! ...

  6. 数据结构实习-迷宫(基于Qt实现)

    预览效果: Maze.pro文件 #------------------------------------------------- # # Project created by QtCreator ...

  7. 汇编实现HelloWorl!

    hello word~ ASSUME CS:CODE,DS:DATA DATA SEGMENT DB "HELLO WORLD" ;存储要显示的数据 DATA ENDS CODE ...

  8. BZOJ两水题连发~(BZOJ1854&&BZOJ1191)

    前言:两题都是省选题不过水的惊人,且都可以用二分图最大匹配做哎--- 1854: [Scoi2010]游戏 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: ...

  9. 深入理解DOM事件类型系列第六篇——加载事件

    前面的话 提到加载事件,可能想到了window.onload,但实际上,加载事件是一大类事件,本文将详细介绍加载事件 load load事件是最常用的一个事件,当页面完全加载后(包括所有图像.java ...

  10. OSS.Common扩展.Net Standard支持实例分享

    上篇(.Net基础体系和跨框架开发普及)介绍了.Net当前生态下的大概情况,也分享了简单实现的过程,这篇文章就是讲解我的OSS.Common项目扩展.Net Standard 支持的过程,主要集中在: ...