#include <stdio.h>
#include<malloc.h>
#include <string.h>
typedef struct student
{
char name[20];
int score;
struct student *next;
}stu;
stu * chuangjian(int );
void shifang(stu *);
void shuchu(stu *);
stu * chazhao(stu *,stu[]);
void pai(stu[],int);
int main(void)
{
int n,i;
printf("请输入有几个人");
scanf("%d",&n);
stu *h;
stu aa[]={0};
for(i=0;i<n+1;i++)
{
aa[i].score=0;
}
h=chuangjian(n);
for(i=0;i<n;i++)
{
h=chazhao(h,aa);
shuchu(h);
printf("\n");
//pai(aa,n);
//printf("\n");
}
pai(aa,n);
shifang(h);
shuchu(h);
}
stu * chuangjian(int n)
{
stu *head,*pre;
int i;
head=(stu *)malloc(sizeof(stu));
head->next=NULL;
pre=head;
stu *p;
for(i=0;i<n;i++)
{
p=(stu*)malloc(sizeof(stu));
printf("请输入第%d个人的名字\n",i);
scanf("%s",p->name);
printf("请输入第%d个人的分数\n",i);
scanf("%d",&p->score);
pre->next=p;
p->next=NULL;
pre=p;
}
return head;
}
void shifang(stu *pre)
{
stu *p;
p=pre->next;
free(pre);
int i;
for(i=0;p!=NULL;i++)
{
pre=p;
free(p);
p=pre->next;
}
}
void shuchu(stu *pre)
{
pre=pre->next;
for(;pre!=NULL;)
{
printf("%s\t%d",pre->name,pre->score);
pre=pre->next;
}
}
stu * chazhao(stu *head,stu aa[])
{
static int i=0;
stu *pre,*p;
pre=head;
p=pre->next;
for(;p!=NULL;)
{
if((p->score)>aa[i].score)
{
aa[i].score=p->score;
strcpy(aa[i].name,p->name);
pre=p;
p=pre->next;
}else
{
pre=p;
p=pre->next;
}
}
pre=head;
p=pre->next;
printf("!!!!!!!!!!!!!!!%s\t%d",aa[i].name,aa[i].score);
for(;p!=NULL;)
{
if((p->score)==aa[i].score)
{
pre->next=p->next;
free(p);
p=pre->next;
}else
{
pre=p;
p=pre->next;
}
}
i++;
return head;
}
void pai(stu aa[],int n)
{
static int i=0;
for(;i<n;i++)
{
printf("%s\t%d",aa[i].name,aa[i].score);
}
}
大哥哥,多谢,我看到你的回答有灵感了,我一改,行了。谢谢,能给个联系方式吗
追答zh_tkj_1@163.com