代码来了。。。
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct LNode{
char data;
struct LNode *next;
} ;
typedef struct LNode node;
node * creatp(void);
void main()
{
node *p,*q,*head1;
int day=1,i=0;
head1=creatp();
p=q=head1;
while(day-i<=300)
{ q=p;
if((day-i)%7==0 || (day-i)%100==0)
{i++;
day++;}
else
p=p->next;
day++;
}
printf("三次返厂之前工作的城市是:%c\n",q->data);
}
node *creatp()
{ node *head,*p,*rear;//定义指针变量
int x=1;
char a;
head=(struct LNode *)malloc(sizeof(struct LNode));/*申请 struct list 类型字节长的存储空间,第一个括号中内容表示将申请空间的首地址经过强制类型转换为struct list *型并把转换后的首地址存储在指针head中;*/
rear=head;//用一个需要移动的指针 rear 来存放头结点的地址
puts("input name of the list :\n");
while(x<=22)
{ scanf("%c",&a);//输入值
p=(struct LNode *)malloc(sizeof(struct LNode));
p->data=a;//将输入的值取出一个值并存储在结点 p 的数据域中
rear->next=p;//将结点 p 的首地址存放在 p 的前驱结点的指针域中
rear=p;//rear指针后移到下一个结点
x++;
}
rear->next=head;//指针 rear 移至最后一个结点处,将此结点的指针域指向头结点
return (head->next);//函数结束时返回创建的单链表的头指针(此头指针指向的结点为输入的第一个数值所存放的结点)
}
[
本帖最后由 comewest 于 2014-12-7 00:20 编辑 ]