zoukankan      html  css  js  c++  java
  • Web Navigation

    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
     1 Source Code
     2 
     3 Problem: 1028        User: 13408100238
     4 Memory: 200K        Time: 0MS
     5 Language: C++        Result: Accepted
     6 Source Code
     7 #include"iostream"
     8 #include"cstring"
     9 #include"string"
    10 #include"stack"
    11 using namespace std;
    12 int main()
    13 {
    14     stack<string> s1,s2;
    15     string s,ss;
    16     s="http://www.acm.org/";
    17     s1.push(s);
    18     while(cin>>s)
    19     {
    20         if(s=="QUIT")
    21            break;
    22         if(s=="VISIT")
    23         {
    24             cin>>ss;
    25             cout<<ss<<endl;
    26             s1.push(ss);
    27             while(!s2.empty())
    28                s2.pop();
    29         }
    30         else if(s=="BACK")
    31         {
    32             //cout<<"back  "<<s1.size()<<endl;
    33             if(s1.size()>=2)
    34             {
    35                 s2.push(s1.top());
    36                 s1.pop();
    37                 cout<<s1.top()<<endl;
    38             }
    39             else
    40                cout<<"Ignored"<<endl;
    41         }
    42         else if(s=="FORWARD")
    43         {
    44             if(!s2.empty())
    45             {
    46                 cout<<s2.top()<<endl;
    47                 s1.push(s2.top());
    48                 s2.pop();
    49             }
    50             else 
    51               cout<<"Ignored"<<endl;
    52         }
    53     }
    54     return 0;
    55 } 
    View Code
  • 相关阅读:
    pycharm 快捷键
    jquery .on
    javaweb项目的优化
    python笔记
    git上解决代码冲突(merge版)
    OpenERP里面继承的用法
    OpenERP新手易犯错误之res.model
    bootstrap 仿实例
    深入理解Binder(二),Binder是什么?
    深入理解Binder(一),从AIDL谈起
  • 原文地址:https://www.cnblogs.com/767355675hutaishi/p/3760922.html
Copyright © 2011-2022 走看看