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 }
  • 相关阅读:
    mysql基础学习
    Linux退出状态码
    python psutil简单示例
    linux systemctl 常用用法简介
    (转)linux进程的地址空间,核心栈,用户栈,内核线程
    (转)NAT原理与NAT穿越
    (转)蜜果私塾:http协议学习系列——协议详解篇
    (转)Windows 7下安装配置PHP+Apache+Mysql环境教程
    (转)蜜果私塾:http协议学习和总结系列 ——协议详解篇
    (转)Linux Futex的设计与实现
  • 原文地址:https://www.cnblogs.com/Deribs4/p/4675404.html
Copyright © 2011-2022 走看看