poj1028

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;
}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值