• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 21, comments - 2, trackbacks - 0, articles - 0

            ZOJ 1061 Web Navigation_數據結構_棧

            Posted on 2011-09-05 22:47 acpeng 閱讀(563) 評論(0)  編輯 收藏 引用 所屬分類: ACM程序
            http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=61
            數據結構,用C寫的棧,不用STL確實復雜多了,WA了幾次~
            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 <url>: 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/


            This problem contains multiple test cases!

            The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

            The output format consists of N output blocks. There is a blank line between output blocks.


            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

            1

            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

            AC代碼:

            #include<stdio.h>
            #include
            <string.h>
            #include
            <malloc.h>
            #define StackSize 105
            typedef 
            struct
            {
                
            char elemt[StackSize][73];
                
            int top;
            }
            Stack;
            void InitStack(Stack *S)
            {
                  S
            ->top=-1;
            }

            int ElemtNum(Stack *S)
            {
                
            return (S->top)+1;
            }

            int IsFull(Stack *S)
            {
                
            return(S->top==StackSize-1?1:0);
            }

            int PushStack(Stack *S,char *x)
            {
                
            if(IsFull(S))  
                    
            return 0;
                S
            ->top++;
                memset(S
            ->elemt[S->top],'\0',sizeof(S->elemt[S->top]));
                strcpy(S
            ->elemt[S->top],x);
                
            return 1;
            }

            int PopStack(Stack *S,char *x)
            {  
                
            if(ElemtNum(S)==0)
                    
            return 0;
                memset(x,
            0,sizeof(x));
                  strcpy(x,S
            ->elemt[S->top]);
                memset(S
            ->elemt[S->top],0,sizeof(S->elemt[S->top]));
                S
            ->top--;
                  
            return 1;
            }

            int GetTopElemt(Stack *S,char *x)
            {
                
            if(ElemtNum(S)==0)
                    
            return 0;
                  memset(x,
            0,sizeof(x));
                  strcpy(x,S
            ->elemt[S->top]);
                  
            return 1;
            }

            int main()
            {
                Stack 
            *sBack,*sForward;
                sBack
            =(Stack *)malloc(sizeof(Stack));
                sForward
            =(Stack *)malloc(sizeof(Stack));
                
            int T;char str[73]="\0",comd[8]="\0",tmp[73]="\0";
                scanf(
            "%d",&T);
                
            while(T--)
                
            {
                    InitStack(sBack); InitStack(sForward);
                    PushStack(sBack,
            "http://www.acm.org/");
                    
            while(1)
                    
            {
                        memset(comd,
            0,sizeof(comd));
                        scanf(
            "%s",comd);
                        
            if(strcmp(comd,"BACK")==0)
                        
            {
                            
            if(ElemtNum(sBack)==1)
                            
            {
                                printf(
            "Ignored\n");
                                
            continue;
                            }

                            PopStack(sBack,tmp);
                            PushStack(sForward,tmp);
                            
            if(GetTopElemt(sBack,tmp)==1)
                                printf(
            "%s\n",tmp);
                        }

                        
            else if(strcmp(comd,"FORWARD")==0)
                        
            {
                            
            if(ElemtNum(sForward)==0)
                            
            {
                                printf(
            "Ignored\n");
                                
            continue;
                            }

                            PopStack(sForward,tmp);
                            PushStack(sBack,tmp);
                            
            if(GetTopElemt(sBack,tmp)==1)
                                printf(
            "%s\n",tmp);
                        }

                        
            else if(strcmp(comd,"VISIT")==0)
                        
            {
                            memset(str,
            0,sizeof(str));
                            scanf(
            "%s",str);
                            printf(
            "%s\n",str);
                            PushStack(sBack,str);
                            InitStack(sForward);
                        }

                        
            else if(strcmp(comd,"QUIT")==0)
                            
            break;
                    }

                    
            if(T>0) printf("\n");
                }

                free(sBack);free(sForward);
                
            return 0;
            }


            亚洲国产成人乱码精品女人久久久不卡| 国产精品久久久久久久久免费| 88久久精品无码一区二区毛片| 69SEX久久精品国产麻豆| 久久国产精品久久国产精品| 久久久久无码精品| 久久WWW免费人成一看片| 精品久久久久久综合日本| 日韩中文久久| 久久综合久久综合久久| 国产精品久久久久久久久久影院| 久久久久人妻精品一区| 色99久久久久高潮综合影院| 国产亚洲婷婷香蕉久久精品| 久久中文字幕精品| 国产精品成人99久久久久91gav| 久久强奷乱码老熟女网站| 久久久久无码专区亚洲av| 国产午夜精品理论片久久影视 | 久久精品国产亚洲AV蜜臀色欲 | 蜜桃麻豆www久久国产精品| 熟妇人妻久久中文字幕| 欧美亚洲国产精品久久久久| 亚洲国产二区三区久久| 无码精品久久久久久人妻中字| 少妇久久久久久被弄到高潮| 欧美精品一区二区精品久久| 国内精品久久久人妻中文字幕| 亚洲美日韩Av中文字幕无码久久久妻妇| 久久er国产精品免费观看2| 69久久夜色精品国产69| 国产∨亚洲V天堂无码久久久| 亚洲精品无码久久久影院相关影片 | 一本大道久久香蕉成人网| 久久九色综合九色99伊人| 激情综合色综合久久综合| 久久久久国产一级毛片高清板| 国产精品九九久久免费视频 | 久久婷婷五月综合97色 | 久久99久久成人免费播放| 伊人久久免费视频|