ADD file via upload

main
pqzbgempc 2 days ago
parent d2f15cb799
commit edd0654e9a

@ -0,0 +1,83 @@
#include <stdio.h>
#include <string.h>
typedef struct
{
int id;
int mclass;
char name[20];
float a,b,c;
float total;
}Student;
void sort(Student *person,int len)
{
int i;
int j;
for(i=0;i<len;i++)
{
int k=i;
for(j=i;j<len;j++)
{
if(person[k].mclass>person[j].mclass||(person[k].mclass==person[j].mclass&&person[k].total<person[j].total))
{
k=j;
}
if(k!=i)
{
Student temp=person[i];
person[i]=person[k];
person[k]=temp;
}
}
}
}
void modify(Student *person,int len,Student modifyperson)
{
int i;
for(i=0;i<len;i++)
{
if(person[i].id==modifyperson.id)
{
person[i]=modifyperson;
sort(person,3);
return;
}
}
}
void print(Student *person,int len,Student modifyperson)
{
int classname=0;
int i;
for(i=0;i<len;i++)
{
if(person[i].mclass!=classname)
{
classname=person[i].mclass;
printf("%d ",classname);
}else{
printf(" ");
}
printf("%d %s %.1f %.1f %.1f",person[i].id,person[i].name,person[i].a,person[i].b,person[i].c);
if(person[i].id==modifyperson.id)
{
printf(" modified");
}
printf("\n");
}
}
int main()
{
Student students[]=
{
{10001,11,"Zhang",99.5,88.5,89.5},
{10002,12,"Yang",77.9,56.5,87.5},
{10003,11,"Liang",92.5,99.0,60.5}
};
sort(students,3);
Student modifystudent;
scanf("%d %d %s %f %f %f",&modifystudent.id,&modifystudent.mclass,&modifystudent.name,&modifystudent.a,&modifystudent.b,&modifystudent.c);
sort(students,3);
modify(students,3,modifystudent);
print(students,3,modifystudent);
return 0;
}
Loading…
Cancel
Save