[POJ1028]Web Navigation(栈)
这题是01年East Central North的A题,目测是签到题
Description
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
Output
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(栈)的更多相关文章
- POJ1028 Web Navigation
题目来源:http://poj.org/problem?id=1028 题目大意: 模拟实现一个浏览器的“前进”和“回退”功能.由一个forward stack和一个backward stack实现. ...
- POJ-1028 Web Navigation 和TOJ 1196. Web Navigation
Standard web browsers contain features to move backward and forward among the pages recently visited ...
- 《web全栈工程师的自我修养》读书笔记
有幸读了yuguo<web全栈工程师的自我修养>,颇有收获,故在此对读到的内容加以整理,方便指导,同时再回顾一遍书中的内容. 概览 整本书叙述的是作者的成长经历,通过经验的分享,给新人或者 ...
- 基于LeanCloud云引擎的Web全栈方案
LeanEngine-Full-Stack The FULL STACK DEVELOPER 复杂的项目, 协作分工, 自动化流程,代码组织结构,框架选择,国际化方案等 Generator 或者See ...
- 《web全栈工程师的自我修养》阅读笔记
在买之前以为这本书是教你怎么去做一个web全栈工程师,以及介绍需要掌握的哪些技术的书,然而看的过程中才发现,是一本方法论的书.读起来的感觉有点像红衣教主的<我的互联网方法论>,以一些自己的 ...
- web性能优化 来自《web全栈工程师的自我修养》
最近在看<web全栈工程师的自我修养>一书,作者是来自腾讯的前端工程师.作者在做招聘前端的时候问应聘者web新能优化有什么了解和经验,应聘者思索后回答“在发布项目之前压缩css和 Java ...
- 处女作《Web全栈开发进阶之路》出版了!
书中源码下载地址:https://github.com/qinggee/WebAdvanced 01. 当初决定写博客的原因非常的纯洁:只要每个月写上 4 篇以上博客,月底的绩效奖金就多 500 块. ...
- web技术栈中不可或缺的Linux技术
Web技术最重要的载体便是服务器,服务器运行在公共的网络环境下,为广大的用户提供网页浏览.信息通讯.消息推送等服务,从最开始的硬件服务器到虚拟主机技术,再到虚拟化技术的出现和云概念的兴起,绝大部分都是 ...
- poj 1028 Web Navigation
Web Navigation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31088 Accepted: 13933 ...
随机推荐
- jQuery插件开发详解
我们该如何扩展jQuery呢?主要可以通过下面2个来扩展:$.extend 和 $.fn $.extend如果把jQuery当成一个类,$.extend相当于为该类添加了静态方法extend. < ...
- delphi假死线程堵塞解决办法
Delphi的高效不多说... 俗话说:真正的程序员用C语言,聪明的程序员用Delphi,一点都不假,和C++比它比C++更简单,更容易上手,功能丝毫不逊色C++,比起VB,毫无疑问比VB好多了,重要 ...
- 【angularjs】【学习心得】ng-class总结
原文:http://www.imooc.com/wenda/detail/236998 今天来说一点angularjs中看起来很简单但是实践起来又有不少问题的ng-class吧 ----------- ...
- 利用PHPCMS V9站群功能建立分站
hosts文件就在C:\Windows\system32\drivers\etc\hosts下 用一套CMS软件系统,做多个网站,统一管理,用户可以互通,这就是所谓的站群功能.这对于运营和维护都能节省 ...
- Java 导出Excel的各种尝试
最近的一个项目比较忙,一直没时间过来跟新博客.今天过来分享一下在此项目中遇到的一个小问题:导出Excel:相信导出Excel这个功能是特别常见的,也有很多的方式.好了,不多说了,直接说说自己遇到的各种 ...
- 如何在项目中引入MetaQ消息收发机制
当需要异步发送和接收大量消息时,需要在Crystal项目中引入MetaQ消息收发机制. 关于MetaQ使用的官方例子可参考:https://github.com/killme2008/Metamorp ...
- MyBatis绑定错误--BindingException:Invalid bound statement (not found)
如果出现: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 一般的原因是Mapper i ...
- RabbitMQ安装和使用(和Spring集成)
一.安装Rabbit MQ Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装Rabbit MQ的前提是安装Erlang.通过下面两个连接下载安装3.2.3 版本: 下载并安装 E ...
- ubuntu更换内核版本
一 详细的使用方法见: http://www.xlgps.com/article/310954.html 二 补充: 1 需要删除旧的内核的方法: sudo apt-get remove linux- ...
- 《JAVASCRIPT高级程序设计》Ajax与Comet
Ajax,是Asynchronous JavaScript + XML的简写,这一技术能向服务器请求额外的技术而无需卸载页面,会带给用户更好的体验.Ajax的核心是XMLHttpRequest对象.为 ...