You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
1.7 KiB
84 lines
1.7 KiB
1 year ago
|
#include <stdio.h>
|
||
|
struct stud
|
||
|
{
|
||
|
int num;
|
||
|
int clas;
|
||
|
char name[10];
|
||
|
float math;
|
||
|
float phy;
|
||
|
float eng;
|
||
|
char modf;
|
||
|
};
|
||
|
int main()
|
||
|
{
|
||
|
|
||
|
struct stud stu[10]={{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},
|
||
|
};
|
||
|
struct stud t={};
|
||
|
struct stud ch[1];
|
||
|
scanf("%d %d %s %f %f %f",&ch[0].num,&ch[0].clas,ch[0].name,&ch[0].math,&ch[0].phy,&ch[0].eng);
|
||
|
struct stud*p=stu;
|
||
|
struct stud*p1=ch;
|
||
|
void change(struct stud stu[],struct stud ch[]);
|
||
|
change(p,p1);
|
||
|
int i,j;
|
||
|
for(i=0;stu[i].num!=0;i++)
|
||
|
{
|
||
|
if(stu[i+1].num!=0)
|
||
|
{
|
||
|
for(j=i+1;stu[j].num!=0;j++)
|
||
|
{
|
||
|
if(stu[i].clas>stu[j].clas)
|
||
|
{
|
||
|
t=stu[i];stu[i]=stu[j];stu[j]=t;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for(i=0;stu[i].num!=0;i++)
|
||
|
{
|
||
|
if(stu[i+1].num!=0)
|
||
|
{
|
||
|
for(j=i+1;stu[j].num!=0&&stu[i].clas==stu[j].clas;j++)
|
||
|
{
|
||
|
if(stu[i].math+stu[i].phy+stu[i].eng<stu[j].math+stu[j].phy+stu[j].eng)
|
||
|
{
|
||
|
t=stu[i];stu[i]=stu[j];stu[j]=t;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for(i=0;stu[i].num!=0;i++)
|
||
|
{
|
||
|
if(i==0)printf("%d %d %s %3.1f %3.1f %3.1f",stu[i].clas,stu[i].num,stu[i].name,stu[i].math,stu[i].phy,stu[i].eng);
|
||
|
else
|
||
|
{
|
||
|
if(stu[i].clas==stu[i-1].clas)
|
||
|
{
|
||
|
printf(" %d %s %3.1f %3.1f %3.1f",stu[i].num,stu[i].name,stu[i].math,stu[i].phy,stu[i].eng);
|
||
|
}
|
||
|
else printf("%d %d %s %3.1f %3.1f %3.1f",stu[i].clas,stu[i].num,stu[i].name,stu[i].math,stu[i].phy,stu[i].eng);
|
||
|
}
|
||
|
if(stu[i].modf=='y')
|
||
|
{printf(" modified");}
|
||
|
printf("\n");
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
void change(struct stud stu[],struct stud ch[])
|
||
|
{
|
||
|
int i;
|
||
|
for(i=0;stu[i].num!=0;i++)
|
||
|
{
|
||
|
if(stu[i].num==ch[0].num)
|
||
|
{
|
||
|
stu[i]=ch[0];
|
||
|
stu[i].modf='y';
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|