POJ-1028-Web Navigation

来源:互联网 发布:dota视频软件 编辑:程序博客网 时间:2024/05/16 12:54

比较简单的一个模拟题,根据实际浏览器的操作来做

代码:

#include<cstdio>#include<cstring>#include<iostream>using namespace std;const int maxn=101;char str[maxn][maxn];int main(){    strcpy(str[0],"http://www.acm.org/");    int cnt=0,now=0;    char op[20];    while(scanf("%s",op)!=EOF)    {if(!strcmp(op,"QUIT"))    break;if(!strcmp(op,"VISIT")){    cnt=now;    scanf("%s",str[++cnt]);    now=cnt;    printf("%s\n",str[now]);}else if(!strcmp(op,"BACK")){    now--;    if(now<0)    {printf("Ignored\n");now=0;    }    elseprintf("%s\n",str[now]);}else{    now++;    if(now>cnt)    {printf("Ignored\n");now=cnt;    }    elseprintf("%s\n",str[now]);}    }    return 0;}


原创粉丝点击