一、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.

二、题解

        这是挺水的一道题,首先题目就挺简单的(英语除外)还告诉我们怎么一步步做。要是看懂了英文题目完全可以照着做就行了。但是我这道题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);
} }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

最新文章

  1. CMD打包文件,解压文件
  2. AngularJS深入(5)——provider
  3. SSH开发实践part4:Spring整合Struts
  4. 分析 &quot;ADO&quot; &quot;ADODB&quot; &quot;ADODC&quot; 之间的区别与联系
  5. Python调试工具-Spyder
  6. 【USACO 3.2.2】二进制数01串
  7. CSS,点击去除虚线边框代码
  8. Spring MVC 时间字符串 @PathVariable获取
  9. redis简单配置
  10. VS 2013--工程的创建,scanf报错,常用快捷键,行号设置
  11. Java学习路径:不走弯路,这是一条捷径
  12. 分享一个SQLSERVER脚本
  13. 【特效】单选按钮和复选框的美化(只用css)
  14. nyoj 黑色帽子
  15. react-native 简介及环境
  16. slave have equal MySQL server UUIDs
  17. Confluence 6 升级自定义的站点和空间关闭缓存
  18. CENTOS7 SYSTEMD SERVICE 将自己的程序放入自动启动的系统服务
  19. 使用VS2013进行C#程序的单元测试
  20. 【VSC】.txt文件打开乱码

热门文章

  1. 5.设计模式----prototype原型模式
  2. 我的Android进阶之旅------>Android自定义窗口标题实例
  3. 纪念下自学QT 第十天 终于写成了串口调试助手
  4. Django——自定义分页(可调用)
  5. iOS swift 语句只能写在函数体内
  6. 认识CoreData—使用进阶
  7. 每天一个Linux命令(17)whereis命令
  8. python 批量修改预定字符串并将修改后的字符串插入文件指定位置
  9. js琐碎知识点
  10. python安装包的方式