日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

poj 1208 Web Navigation(堆栈操作)

發(fā)布時(shí)間:2023/12/19 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 poj 1208 Web Navigation(堆栈操作) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一、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.
二、題解
??????? 這是挺水的一道題,首先題目就挺簡(jiǎn)單的(英語(yǔ)除外)還告訴我們?cè)趺匆徊讲阶觥R强炊擞⑽念}目完全可以照著做就行了。但是我這道題RE4次,最后發(fā)現(xiàn)是有幾句if判斷省了括號(hào)。以后不能偷懶了,改寫的一定要寫上。
三、題解
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);}} }

版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。

轉(zhuǎn)載于:https://www.cnblogs.com/AndyDai/p/4734158.html

總結(jié)

以上是生活随笔為你收集整理的poj 1208 Web Navigation(堆栈操作)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。