|
|
|
|
#include<stdio.h>
|
|
|
|
|
#include<stdlib.h>
|
|
|
|
|
typedef struct {
|
|
|
|
|
int ID;
|
|
|
|
|
int classnumber;
|
|
|
|
|
float score1,score2,score3;
|
|
|
|
|
}student;
|
|
|
|
|
|
|
|
|
|
void insert(student students[],int *n,student new){
|
|
|
|
|
int k=0;
|
|
|
|
|
int j=*n-1;
|
|
|
|
|
for( k;k<=*n;k++){
|
|
|
|
|
if(k==*n||students[k].classnumber>new.classnumber){
|
|
|
|
|
for( j;j>=k;j--){
|
|
|
|
|
students[j+1]=students[j];
|
|
|
|
|
}
|
|
|
|
|
students[k]= new;
|
|
|
|
|
(*n)++;
|
|
|
|
|
break;
|
|
|
|
|
}else if(students[k].ID==new.ID){
|
|
|
|
|
printf("<EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD>Ϣ\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int compare(const void*a,const void *b){
|
|
|
|
|
student s1=*(student*)a;
|
|
|
|
|
student s2=*(student*)b;
|
|
|
|
|
if(s1.classnumber!=s2.classnumber){
|
|
|
|
|
return s1.classnumber-s2.classnumber;
|
|
|
|
|
}
|
|
|
|
|
float total1=s1.score1+s1.score2+s1.score3;
|
|
|
|
|
float total2=s2.score1+s2.score2+s2.score3;
|
|
|
|
|
return total2-total1;
|
|
|
|
|
}
|
|
|
|
|
int main(){
|
|
|
|
|
int n=3;
|
|
|
|
|
student students[5]={
|
|
|
|
|
{10001,11,99.5,88.5,89.5},
|
|
|
|
|
{10002,12,77.9,56.5,87.5},
|
|
|
|
|
{10003,11,92.5,99.0,60.5}};
|
|
|
|
|
student new;
|
|
|
|
|
scanf("%d %d %f %f %f", &new.ID, &new.classnumber,&new.score1, &new.score2, &new.score3);
|
|
|
|
|
insert(students,&n,new);
|
|
|
|
|
qsort(students,n,sizeof(student),compare);
|
|
|
|
|
int i=0;
|
|
|
|
|
for( i;i<n;i++){
|
|
|
|
|
printf("%d %d %.1f %.1f %.1f",students[i].ID,students[i].classnumber,students[i].score1,students[i].score2,students[i].score3);
|
|
|
|
|
if(students[i].ID==new.ID){
|
|
|
|
|
printf(" inserted\n");
|
|
|
|
|
}else{
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|