poj 1208 Web Navigation(堆栈操作)
一、Description
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
in each stack at any time. The end of input is indicated by the QUIT command.
Output
is produced for the QUIT command.
二、题解
这是挺水的一道题,首先题目就挺简单的(英语除外)还告诉我们怎么一步步做。要是看懂了英文题目完全可以照着做就行了。但是我这道题RE4次,最后发现是有几句if判断省了括号。以后不能偷懒了,改写的一定要写上。
三、题解
import java.util.Scanner;
import java.util.Stack; public class Main { public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
Stack<String> forward=new Stack<String>();
Stack<String> backward=new Stack<String>();
String current="http://www.acm.org/";
String order="";
String display="";
while(!(order=sc.next()).equals("QUIT")){
if(order.equals("VISIT")){
backward.push(current);
current=sc.next();
forward.clear();
display=current; }else if(order.equals("BACK")){
if(backward.empty()){
display="Ignored";
}
else{
forward.push(current);
current=backward.pop();
display=current;
}
}else if(order.equals("FORWARD")){
if(forward.empty()){
display="Ignored";
}
else{
backward.push(current);
current=forward.pop();
display=current; }
}
System.out.println(display);
} }
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
poj 1208 Web Navigation(堆栈操作)的更多相关文章
- poj 1028 Web Navigation
Web Navigation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31088 Accepted: 13933 ...
- poj 1028 Web Navigation(模拟)
题目链接:http://poj.org/problem? id=1028 Description Standard web browsers contain features to move back ...
- poj 1028 Web Navigation 【模拟题】
题目地址:http://poj.org/problem?id=1028 测试样例: Sample Input VISIT http://acm.ashland.edu/ VISIT http://ac ...
- POJ 1028 Web Navigation 题解
考查代码能力的题目.也能够说是算法水题,呵呵. 推荐新手练习代码能力. 要添加难度就使用纯C实现一下stack,那么就有点难度了,能够使用数组模拟环形栈.做多了,我就直接使用STL了. #includ ...
- POJ 1028:Web Navigation
Web Navigation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30828 Accepted: 13821 ...
- POJ 1208 模拟
2017-08-28 15:07:16 writer:pprp 好开心,这道题本来在集训的时候做了很长很长时间,但是还是没有做出来,但是这次的话,只花了两个小时就做出来了 好开心,这次采用的是仔细分析 ...
- POJ1028 Web Navigation
题目来源:http://poj.org/problem?id=1028 题目大意: 模拟实现一个浏览器的“前进”和“回退”功能.由一个forward stack和一个backward stack实现. ...
- pb对Web Service的操作可使用两种方式实现
从PB8.0/9.0开始,就已经提供Web Service Proxy功能,能够直接进行相关程序的编写. 但是,部分老项目使用PB6.5开发 研究后发现,其实PB6.5要操作Web Service也挺 ...
- 一步步写STM32 OS【三】PendSV与堆栈操作
一.什么是PendSV PendSV是可悬起异常,如果我们把它配置最低优先级,那么如果同时有多个异常被触发,它会在其他异常执行完毕后再执行,而且任何异常都可以中断它.更详细的内容在<Cortex ...
随机推荐
- Android UI Design
Ref:直接拿来用!10款实用Android UI工具 Ref:Android UI设计资源 Ref:Android酷炫实用的开源框架(UI框架) Ref:Android UI 组件 Ref:Andr ...
- 使用idea2017搭建SSM框架(转发:https://www.cnblogs.com/hackyo/p/6646051.html#!comments)
步骤: 一.首先使用idea新建一个Maven webapp项目 点击Finish,第一次搭建可能会很慢,甚至可能需要VPN才能搭建成功 二.搭建目录结构 我这里列出的是搭建完了之后所有的目录和文件, ...
- Java实现时间日期格式转换示例
package com.hanqi.util; import java.text.ParseException; import java.text.SimpleDateFormat; import j ...
- ubunbu退出nano
无意中进入ubuntu GNU nano ctrl+x即可退出
- Java多线程系列 JUC线程池04 线程池原理解析(三)
转载 http://www.cnblogs.com/skywang12345/p/3509954.html https://blog.csdn.net/qq_22929803/article/det ...
- China sets economic reform priorities for 2015
BEIJING -- China's State Council, the cabinet, on Monday unveiled this year's priorities for economi ...
- [Vue] 初识Vue-常用指令
Vue Vue是一套用于构建用户界面的渐进式框架, Vue的核心库只关注视图层,不仅易于上手,还便于与第三方库或既有项目整合.Vue是一个JavaScript MVVM库, 以数据驱动和组件化的思想构 ...
- Java大坑之Integer对象比较相等
public class IntegerTest { /*** * 对于Integer var = ? 在 -128到127之间的复制,Integer对象是在IntegerCache.cache产生 ...
- Web container==Servlet container
Web container From Wikipedia, the free encyclopedia (Redirected from Servlet container) Web co ...
- meta 标签代码解决IE兼容问题,IE6,IE7,IE8,IE9,IE10(包括360的兼容模式)
最近做了一个项目,客户反映,在360下布局错位,远程调试了一下,发现客户使用的是360的兼容模式,然而我在自己的电脑上测试的时候是正常的(兼容模式也正常):简单研究了一下360的兼容模式,在360的兼 ...