zoukankan      html  css  js  c++  java
  • CDZSC_2015寒假新人(4)——搜索

    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
    

      

    题解:模拟题。利用到的栈的思想,但用不了STL的栈,可以自己简单的实现一个栈。没有什么难点。详见代码。

     
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 const int MAX = 128;
     5 
     6 struct URL{
     7     char a[MAX][MAX];
     8     int dir, max;
     9 
    10     void create(){dir = 0; max = 0; memset(a, 0, sizeof(a)); strcpy(a[0], "http://www.acm.org/");}
    11     bool back(){if(dir > 0)   {dir--; return true;} return false;}
    12     bool fwd() {if(dir < max) {dir++; return true;} return false;}
    13     void viw(char * str) {strcpy(a[++dir], str); max = dir;}
    14     void show(){printf("%s
    ", a[dir]);}
    15 };
    16 
    17 URL url;
    18 
    19 int main()
    20 {
    21 #ifdef CDZSC_OFFLINE
    22     freopen("in.txt", "r", stdin);
    23     freopen("out.txt", "w", stdout);
    24 #endif
    25     char str[MAX];
    26     url.create();
    27     while(~scanf("%s", str))
    28     {
    29         switch(str[0])
    30         {
    31         case 'V': scanf("%s", str); url.viw(str); url.show(); break;
    32         case 'F': if(url.fwd()) url.show(); else printf("Ignored
    "); break;
    33         case 'B': if(url.back()) url.show(); else printf("Ignored
    "); break;
    34         case 'Q': url.create(); break;
    35         }
    36     }
    37     return 0;
    38 }
    View Code
  • 相关阅读:
    AlphaMobileControls
    .NET Compact Framework下注册表导出工具的开发
    windows moblie 5.0在托管程序中实现短信接收和拦截
    自定义MessageBox
    Windows Mobile 背景灯控制
    windows Mobile 启动Mobile Office
    windows mobile 5.0 进程管理、窗体管理、重启和关闭操作系统
    让Windows Mobile模拟器通过你的PC上网
    Windows Mobile获取存储卡容量及使用情况
    透明背景
  • 原文地址:https://www.cnblogs.com/LiuACG/p/4251032.html
Copyright © 2011-2022 走看看