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 ...
随机推荐
- iOS 开发与H5交互(JavaScriptCore框架的使用)
现在的iOS项目中嵌入了越来越多的Web界面,当然是为了方便,那么为了迎合这一趋势,作为iOS开发程序员,我们必须要了解怎么样用OC去和这些Web界面进行交互.这里介绍的是JavaScriptCore ...
- ansible copy文件比较慢, 使用Synchronize模块
Ansible中的同步模块(rsync) Synchronize模块 1 2 3 4 5 6 7 This is a wrapper around rsync. Of course you cou ...
- 《程序员代码面试指南》第一章 栈和队列 构造数组的MaxTree
题目 给出一个无重复元素的数组,构造此数组的MaxTree, java代码 /** * @Description: 构造数组的MaxTree * @Author: lizhouwei * @Creat ...
- 第三篇 css属性
一.颜色属性 颜色属性有下面四种方式 <div style="color:blueviolet">ppppp</div> <div style=&qu ...
- hbase shell-ddl(表定义指令)
hbase表定义指令详细解说篇 1. alter, alter_async, alter_status 2. create 3. describe (可以简写成'desc') 显示某张表的结构情况 ...
- Nginx初步配置
编辑 简介 Nginx ("engine x") 是一个轻量级,高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为 ...
- DL一(ML基础知识)
基础知识ML 在进行深度学习前,根据学习网站的建议,首先学习机器学习的基础课程,学习资料主要是Andrew讲的ShortVideo,网址:http://openclassroom.stanford.e ...
- 红米.USB安装_无法打开
1.必须有 SIM卡,才能打开 USB安装 红米1s(miui8.5)就是这样 2. 3. 4. 5.
- 红米note.线刷
1.第一代 红米note 时间:20180121 这次 线刷之后,摄像头还是模糊,扫描小一点的二维码的时候 还是一片模模糊糊... 2.ZC:我下载的“通用刷机工具”名为:MiFlash2017-12 ...
- 仿联想商城laravel实战---4、验证(lavarel的表单验证如何使用)
仿联想商城laravel实战---4.验证(lavarel的表单验证如何使用) 一.总结 一句话总结: 验证规则和验证信息的数组:在控制器的方法中 1.注册页面中的用户名正确(比如是否重名,字段长度是 ...