毫无意义的一遍bk,可能这东西以后有用?
(又复杂又佣长)
一道为了链表而链表的c语言题目
cc-test08-1链表的输入与输出
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
struct student
{
int num;
char name[25];
char xb;
double score[5];
double ave;
double sum;
struct student* next;
};
void swap1(struct student *x,struct student *p)
{
struct student t;
t=*x;
struct student *s1,*s2;
s1=x->next;
s2=p->next;
*x=*p;
x->next=s1;
*p=t;
p->next=s2;
}
void sort1(struct student *head)
{
struct student *p=head;
while(p!=NULL)
{
struct student *x=p->next;
while(x!=NULL)
{
if(x->sum>p->sum)
{
swap1(x,p);
}
x=x->next;
}
p=p->next;
}
}
int main()
{
int n;
scanf("%d",&n);
struct student *head,*p1,*p2;
p1=(struct student *)malloc(sizeof(struct student));
head=p1;
scanf("%d%*c%[^\n]%*c%c%lf%lf%lf",&p1->num,p1->name,&p1->xb,&p1->score[1],&p1->score[2],&p1->score[3]);
p1->sum=p1->score[1]+p1->score[2]+p1->score[3];
p1->ave=p1->sum/3;
while(--n)
{
p2=(struct student *)malloc(sizeof(struct student));
p1->next=p2;
scanf("%d%*c%[^\n]%*c%c%lf%lf%lf",&p2->num,p2->name,&p2->xb,&p2->score[1],&p2->score[2],&p2->score[3]);
p2->sum=p2->score[1]+p2->score[2]+p2->score[3];
p2->ave=p2->sum/3;
p2->next=NULL;
p1=p2;
}
sort1(head);
p1=head;
while(p1!=NULL)
{
printf("%d %s %c %.2lf %.2lf %.2lf %.2lf %.2lf\n",p1->num,p1->name,p1->xb,p1->score[1],p1->score[2],p1->score[3],p1->ave,p1->sum);
p1=p1->next;
}
return 0;
}