# 第三次作业

#### 输出月份英文名

char *getmonth( int n )
{
if(n<=0||n>12)
{
return NULL;
}else
{
if(n==1)
{
return "January";
}
if(n==2)
{
return "February";
}
if(n==3)
{
return "March";
}
if(n==4)
{
return "April";
}
if(n==5)
{
return "May";
}
if(n==6)
{
return "June";
}
if(n==7)
{
return "July";
}
if(n==8)
{
return "August";
}
if(n==9)
{
return "September";
}
if(n==10)
{
return "October";
}
if(n==11)
{
return "November";
}
if(n==12)
{
return "December";
}
}
}


#### 查找星期

int getindex( char *s )
{
int i;
char a[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
for(i=0;i<7;i++)
{
if(strcmp(s,a[i])==0)
{
return i;
}
}
if(i==7)
{
return -1;
}
}


#### 计算最长的字符串长度

int max_len( char *s[], int n )
{
int i;
int max=strlen(s[0]);
for(i=1;i<n;i++)
{
if(strlen(s[i])>max)
{
max=strlen(s[i]);
}
}
return max;
}


#### 指定位置输出字符串

char *match( char *s, char ch1, char ch2 )
{
int i=0,j=0,k=0,x=0;
char *p=NULL;
x = strlen(s);
for(i=0;i<x;i++)
{
if(s[i]==ch1)
{
p=&s[i];
for(j=i;j<x;j++)
{
if(s[j]!=ch2)
{
printf("%c", s[j]);
}
if(s[j]==ch2)
{
printf("%c\n", s[j]);
return p;
}
}
printf("\n");
return p;
}
}
p=&s[x];
printf("\n");
return p;
}


#### 奇数值结点链表

  struct ListNode *getodd(struct ListNode **L)
{
int flag=0;
while(p!=NULL)
{
q=(struct ListNode*)malloc(sizeof(struct ListNode));
if(p->data%2!=0)
{
q->data=p->data;
q->next=NULL;
{
}else
{
tail1->next=q;
}
tail1=q;
ptr=p;
p=p->next;
free(ptr);
}else
{
{
}else
{
tail2->next=p;
}
tail2=p;
p=p->next;
flag=1;

}
if(flag==1)
{
tail2->next=NULL;
}
}
}


  struct ListNode *readlist()
{
int data;
struct ListNode *head=NULL, *tail=NULL, *p=NULL;

scanf("%d", &data);
while (data != -1)
{
p = (struct ListNode*) malloc(sizeof(struct ListNode));
p->data = data;
p->next = NULL;
if (head == NULL)
else
tail->next = p;
tail = p;
scanf("%d", &data);
}
}

struct ListNode *getodd(struct ListNode **L)
{
int flag = 0;
struct ListNode *head=NULL, *tail=NULL, *q=NULL, *p=*L, *p1=NULL, *p2=NULL, *ptr=NULL;

while (p!=NULL)
{
if (p->data % 2 != 0)
{
q = (struct ListNode *) malloc(sizeof(struct ListNode));
q->data = p->data;
q->next = NULL;
if (head == NULL)
else
tail->next = q;
tail = q;
ptr = p;
p = p->next;
free(ptr);
}
else
{
if (p1 == NULL)
p1 = p;
else
p2->next = p;
p2 = p;
p = p->next;
flag = 1;
}
}
if (flag==1)
p2->next = NULL;
*L = p1;
}


#### 学生成绩链表处理

struct stud_node *deletelist( struct stud_node *head, int min_score )
{
{
return NULL;
}else
{
{

if(p->score<min_score)
{

{
}else
{
if(p->next == NULL )
{

p1->next = NULL;
free(p);
}
p1->next=p->next;
}
free(p);
}
p1=p;
}
}
}


struct stud_node *createlist()
{
struct stud_node *head= NULL, *tail= NULL, *q= NULL;
int num;
char name[200];
int score;
scanf ("%d", &num);
while (num != 0)
{
q = (struct stud_node *)malloc (sizeof (struct stud_node));
scanf ("%s%d", q->name, &q->score);
q->num = num;
q->next = NULL;
if (head == NULL)
else
tail->next = q;
tail = q;
scanf ("%d", &num);
}
}
struct stud_node *deletelist( struct stud_node *head, int min_score )
{
{
return NULL;
}else
{
{
if(p->score<min_score)
{
{
free(p);
continue;
}
if(p->next == NULL )
{

p1->next = NULL;
free(p);
}
p1->next=p->next;
free(p);
p=p->next;  continue;
}
p1=p;
p=p->next;
}
}
}


#### 链表拼接

struct ListNode *mergelists(struct ListNode *list1, struct ListNode *list2)
{

int n=0,a[10000];
struct ListNode *p=list1;
while(p!=NULL)
{
a[n]=p->data;
p=p->next;
n++;
}
p=list2;
while(p!=NULL)
{
a[n]=p->data;
p=p->next;
n++;
}
int i,j,t;
for(j=0;j<n-1;j++)
{
for(i=0;i<n-1-j;i++)
{
if(a[i]>a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}
}
for(i=0;i<n;i++)
{
q=(struct ListNode *)malloc(sizeof(struct ListNode));
q->data=a[i];
q->next=NULL;