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 }
  • 相关阅读:
    git/gerrit上已经删除了远程分支,本地仍然能看到的解决方法
    bat中查找文件夹下有几个某类型的文件
    ERROR 1045 (28000)问题解决
    Unsupervised Pretraining Transfers well Across Languages
    由声学特征重建语音波形-声码器的最近进展
    神经机器翻译中有用的技巧
    多语种神经机器翻译
    利用Fairseq训练新的机器翻译模型
    转:Linux 系统忘记密码 -> 修改 Ubuntu 虚拟机密码
    Linux安装与配置Tomcat
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4675404.html
Copyright © 2011-2022 走看看