这题是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. rsync 实验

    参考1:http://www.jb51.net/LINUXjishu/142722.html 参考2:http://sookk8.blog.51cto.com/455855/328076 主服务器IP ...

  2. %c输入应注意的问题

    for(i=0;i<n;i++) { getchar(); scanf("%c",&str[i]); } 这样输入是错的 的这样输入 for(i=0;i<n;i ...

  3. js原生继承之——组合式继承实例

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  4. ZOJ-2343-Robbers

    题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1398 题意: 输入t 有t个测试用例每个测试用例第一行输入三个数n, ...

  5. JS前端的分享功能

    给网页加上分享代码,借助网友的力量推广网站,目前已经很流行了 以下是网页代码 QQ空间分享代码如下: <a href="javascript:void(0);" onclic ...

  6. IIS7和Tomcat7整合,即IIS7和Tomcat共用80端口

    IIS7和Tomcat7整合,即IIS7和Tomcat共用80端口 背景: 最近公司有一个项目要上线,需要用到iis和tomcat整合,共用80端口.由于公司的数据都非常重要,只通过端口映射到外网的8 ...

  7. 大型网站制作前端使用PHP后台逻辑用 Java

    对于网站团队,大概可以按照职责分为前端.后端.架构三种角色. 前端:负责所有和用户有交互的产品,包括 WEB以及手机客户端 后端:负责各种业务 API 的开发,以及服务器端其他系统的开发 架构:负责设 ...

  8. (转)java生成UUID通用唯一识别码 (Universally Unique Identifier)

    (原文链接:http://blog.csdn.net/carefree31441/article/details/3998553)   UUID含义是通用唯一识别码 (Universally Uniq ...

  9. Java泛型类定义,与泛型方法的定义使用

    package com.srie.testjava; public class TestClassDefine<T, S extends T> { public static void m ...

  10. 以Tomcat+Mysql为例,实现Docker多容器连接

    Docker提供了多个容器直接访问的方法,最简单的方式是直接使用端口映射-p参数指定映射的端口或者-P映射所有端口,多个容器直接通过网络端口进行访问. 但网络端口映射方式并不是Docker中连接多个容 ...