ADD file via upload

main
pfwtzfkoe 1 year ago
parent 900ea069a7
commit 66f7f469ac

@ -0,0 +1,82 @@
#include <stdio.h>
#include <string.h>
typedef struct
{
int id;
int class;
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].class>person[j].class||(person[k].class==person[j].class&&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].class!=classname)
{
classname=person[i].class;
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.class,&modifystudent.name,&modifystudent.a,&modifystudent.b,&modifystudent.c);
sort(students,3);
modify(students,3,modifystudent);
print(students,3,modifystudent);
return 0;
}
Loading…
Cancel
Save