zoukankan      html  css  js  c++  java
  • poj 1028 Web Navigation

    Web Navigation
    Time Limit: 1000MS   Memory Limit: 10000K
    Total Submissions: 31088   Accepted: 13933

    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.

    Sample Input

    VISIT http://acm.ashland.edu/
    VISIT http://acm.baylor.edu/acmicpc/
    BACK
    BACK
    BACK
    FORWARD
    VISIT http://www.ibm.com/
    BACK
    BACK
    FORWARD
    FORWARD
    FORWARD
    QUIT

    Sample Output

    http://acm.ashland.edu/
    http://acm.baylor.edu/acmicpc/
    http://acm.ashland.edu/
    http://www.acm.org/
    Ignored
    http://acm.ashland.edu/
    http://www.ibm.com/
    http://acm.ashland.edu/
    http://www.acm.org/
    http://acm.ashland.edu/
    http://www.ibm.com/
    Ignored

    Source

     1 //http://poj.org/problem?id=1028
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 #include <queue>
     6 #include <stack>
     7 #include <iostream>
     8 using namespace std;
     9 int main(){
    10     //freopen("D:\INPUT.txt","r",stdin);
    11     stack<string> f,b;
    12     int num=1;
    13     string curs="http://www.acm.org/",news;
    14     //cin>>s&&s!="QUIT"
    15     while(cin>>news&&news!="QUIT"){
    16         //cout<<num++<<"   "<<news<<"   ";
    17         if(news=="BACK"){
    18             if(!b.empty()){
    19                 f.push(curs);
    20                 curs=b.top();
    21                 b.pop();
    22                 cout<<curs<<endl;
    23             }
    24             else{
    25                 printf("Ignored
    ");
    26             }
    27         }
    28         else{
    29             if(news=="FORWARD"){
    30                 if(!f.empty()){
    31                     b.push(curs);
    32                    curs=f.top();
    33                    f.pop();
    34                    cout<<curs<<endl;
    35                 }
    36                 else{
    37                    printf("Ignored
    ");
    38                 }
    39             }
    40             else{
    41                 b.push(curs);
    42                 cin>>curs;
    43                 while(!f.empty()){
    44                     f.pop();
    45                 }
    46                 cout<<curs<<endl;
    47             }
    48         }
    49     }
    50     return 0;
    51 }
  • 相关阅读:
    log4net Appenders
    cnblogs 安家了
    log4net 资源索引贴
    Log2Console A Generic Log Viewer (for Log4Net, NLog...)
    [前端技术]如何加深对JavaScipt中的Math.ceil() 、Math.floor() 、Math.round() 三个函数的理解
    msiexec 命令使用文档
    “安装和部署”文章索引
    一句SQL实现获取自增列操作
    MsChart 部署遇到的一点问题
    [Asp.net]ZipHelper 在线压缩解压帮助类(SharpZipLib组件实现)
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4675404.html
Copyright © 2011-2022 走看看