poj_1028 Web Navigation

来源:互联网 发布:ora27102 windows 编辑:程序博客网 时间:2024/05/17 07:29
#include <stdio.h>#include <stdlib.h>#include <string.h>#define C_MAX 70struct weburl{char url[C_MAX];struct weburl *next;struct weburl *prev;};void  web_navigation(){char temp[70];struct weburl *head = (struct weburl *)malloc(sizeof(struct weburl));struct weburl *p2 = head;struct weburl *p1 =NULL;        struct weburl *tp =NULL;struct weburl *newurl =NULL;strcpy(head->url,"http://www.acm.org/");head->next = NULL;head->prev = NULL;while(scanf("%s",temp)!=EOF){if(strcmp(temp,"BACK") == 0){if(p2->prev != NULL) {p2 = p2->prev;printf("%s\n",p2->url); }else{printf("Ignored\n");}        } else if(strcmp(temp,"FORWARD") == 0){if(p2->next != NULL) {p2 = p2->next;printf("%s\n",p2->url); }else{printf("Ignored\n");}        }else if(strcmp(temp,"VISIT") == 0){newurl = (struct weburl*)malloc(sizeof(struct weburl));scanf("%s",newurl->url);newurl->next = NULL;newurl->prev = p2;p1 = p2->next;p2->next = newurl;p2 = newurl;                        tp =p1;   while(tp != NULL)   {    p1 = p1->next;      free(tp);    tp=p1; } p1 =NULL;printf("%s\n",newurl->url);}else if(strcmp(temp,"QUIT") == 0){  goto exit;}memset(temp,0,sizeof(temp)/sizeof(temp[0]));}exit:   tp = head;   while(tp != NULL)   {      head = head->next;      free(tp);      tp = head;   }   tp =NULL;    p2 =NULL;    newurl =NULL;    head = NULL;}int main(void){  web_navigation();}

0 0
原创粉丝点击