【stack】模拟网页浏览 poj 1028

#include<stdio.h>
#include<string.h>
 
int main()
{
    char s[200][71];
    char str[71];
    int i,depth;
    strcpy(s[0],"http://www.acm.org/");
    i=0;
    depth=0;
    while(1)
    {
        scanf("%s",str);
        if(strcmp(str,"QUIT")==0)
        {
            break;
        }
        if(strcmp(str,"VISIT")==0)
        {
            scanf("%s",&s[++i]);
            printf("%s\n",s[i]);
            depth=i;
        }
        else if(strcmp(str,"BACK")==0)
        {
            if(i>0)
            {
                --i;
                printf("%s\n",s[i]);
            }
            else
            {
                printf("Ignored\n");
            }
        }
        else if(strcmp(str,"FORWARD")==0)
        {
            if(depth>i)
            {
                ++i;
                printf("%s\n",s[i]);
            }
            else
            {
                printf("Ignored\n");
            }
        }
    }
    //system("pause");
    return 0;
}

 

posted @ 2014-10-10 09:48  balfish  阅读(153)  评论(0编辑  收藏  举报