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 }
  • 相关阅读:
    接口隔离原则(Interface Segregation Principle)ISP
    依赖倒置(Dependence Inversion Principle)DIP
    里氏替换原则(Liskov Substitution Principle) LSP
    单一指责原则(Single Responsibility Principle) SRP
    《面向对象葵花宝典》阅读笔记
    智能手表ticwatch穿戴体验
    我所理解的软件工程
    RBAC基于角色的权限访问控制
    程序员健康指南阅读笔记
    我晕倒在厕所了
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4675404.html
Copyright © 2011-2022 走看看