poj1028

来源:互联网 发布:vscode在插件 编辑:程序博客网 时间:2024/05/22 04:31
1、初始化双向链表,头对应首页
2、得到每行第一个字母
{
1、V,得到本行空格以后的内容,接到当前指针后面
2、B,当前指针向前
3、F,当前指针向后
4、Q,退出
若越界,输出Ignored。不执行指针替换
}

需要注意的问题:无用字符怎么略过


#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct node {struct node *forward;char ur[73];struct node *next;}*url;url head;url now;//当前指针void judge(char o){if (o=='B'){if (now->forward==NULL){printf("Ignored\n");}else {now=now->forward;printf("%s\n",now->ur);}while(getchar()!='\n');}else if(o=='F'){if(now->next==NULL)printf("Ignored\n");else {now=now->next;printf("%s\n",now->ur);}while(getchar()!='\n');}else if(o=='V'){while(getchar()!=' ');url p;p=(url)malloc(sizeof(struct node));p->next=NULL;p->forward=now;now->next=p;now=p;gets(now->ur);//getchar();printf("%s\n",now->ur);}}int main(){char tmp;//url head;head=(url)malloc(sizeof(struct node));head->forward=NULL;head->next=NULL;strcpy(head->ur,"http://www.acm.org/");//url now;now=(url)malloc(sizeof(struct node));now=head;scanf("%c",&tmp);while(tmp!='Q'){judge(tmp);//while(getchar()!='\n');scanf("%c",&tmp);}return 0;}


原创粉丝点击