跳至正文

Web浏览 解题报告

  • OI路程

开到这个题目,想起了浏览器Lynx,用过两次,太难用了,汗,,貌似跑题了。
整个题目就是要了解一下浏览器的向前向后的特性,浏览器向后几步之后再输入网址就不能够向前浏览了。整个程序我就用一个数组来维护的,额,具体的细节看代码吧:

C语言:

#include <stdio.h>
#include <string.h>
#define MAX 10000
char link[MAX][71];
int tail, now;

void add(char *str)
{
 int t = (now + 1) % MAX;
 if(now == MAX){
 exit(-1);
 }
 strcpy(link[t], str);
 now = t;
 tail = now + 1;
}

char *back(void)
{
 if(now == 0){
 return NULL;
 }
 return link[--now];
}

char *forward(void)
{
 if(now + 1 == tail){
 return NULL;
 }
 return link[++now];
}

void init(void)
{
 tail = 0;
 now = -1;
 add(http://www.acm.org/);
}

int main(void)
{
 char *t;
 char command[8], address[71];

 init();
 while(scanf(%s, command)){
 if(strcmp(command, BACK) == 0){
 t = back();
 if(t == NULL){
 printf(Ignored\\n);
 }else{
 printf(%s\\n, t);
 }
 }else if(strcmp(command, FORWARD) == 0){
 t = forward();
 if(t == NULL){
 printf(Ignored\\n);
 }else{
 printf(%s\\n, t);
 }
 }else if(strcmp(command, VISIT) == 0){
 scanf(%s, address);
 add(address);
 printf(%s\\n, address);
 }else{
 break;
 }
 }

 return 0;
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注