题目如下,代码亲测能过
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct student{
int num;
char name[20];
int score;
struct student *next;
};
struct student *Creat();
struct student *Delete(struct student *head,int min);
void Ptrint(struct student *head);
int main()
{
struct student *head;
int min;
head=Creat();
scanf("%d",&min);
head=Delete(head,min);
Ptrint(head);
}
struct student *Creat()
{
struct student *head , *tail , *p;
int num, score;
char name[20];
int size = sizeof(struct student);
head=tail=NULL;
scanf("%d",&num);
while(num != 0){
scanf("%s%d",name,&score);
p=(struct student*)malloc(size);
p->num=num;
strcpy(p->name,name);
p->score=score;
p->next=NULL;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
scanf("%d",&num);
}
return head;
}
struct student *Delete(struct student *head,int min)
{
struct student *a1,*a2;
while(head!=NULL&&head->score<min){
a2=head;
head=head->next;
free(a2);
}
if(head==NULL)
return NULL;
a1=head;
a2=head->next;
while(a2!=NULL){
if(a2->score<min){
a1->next=a2->next;
free(a2);
}
else
a1=a2;
a2=a1->next;
}
return head;
}
void Ptrint(struct student *head)
{
struct student *a;
if(head==NULL)
return;
for(a=head; a; a=a->next)
printf("%d %s %d\n", a->num,a->name,a->score);
}