poj 1208 Web Navigation(堆栈操作)
2024-09-05 06:04:56
一、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/
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.
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.
二、题解
这是挺水的一道题,首先题目就挺简单的(英语除外)还告诉我们怎么一步步做。要是看懂了英文题目完全可以照着做就行了。但是我这道题RE4次,最后发现是有几句if判断省了括号。以后不能偷懒了,改写的一定要写上。
三、题解
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);
} }
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
最新文章
- CMD打包文件,解压文件
- AngularJS深入(5)——provider
- SSH开发实践part4:Spring整合Struts
- 分析 ";ADO"; ";ADODB"; ";ADODC"; 之间的区别与联系
- Python调试工具-Spyder
- 【USACO 3.2.2】二进制数01串
- CSS,点击去除虚线边框代码
- Spring MVC 时间字符串 @PathVariable获取
- redis简单配置
- VS 2013--工程的创建,scanf报错,常用快捷键,行号设置
- Java学习路径:不走弯路,这是一条捷径
- 分享一个SQLSERVER脚本
- 【特效】单选按钮和复选框的美化(只用css)
- nyoj 黑色帽子
- react-native 简介及环境
- slave have equal MySQL server UUIDs
- Confluence 6 升级自定义的站点和空间关闭缓存
- CENTOS7 SYSTEMD SERVICE 将自己的程序放入自动启动的系统服务
- 使用VS2013进行C#程序的单元测试
- 【VSC】.txt文件打开乱码