parent
ef87b827ca
commit
99d098c39b
@ -0,0 +1,55 @@
|
|||||||
|
#include<stdio.h>
|
||||||
|
struct Scoreb{
|
||||||
|
int schoolnumber;
|
||||||
|
int classnumber;
|
||||||
|
char name[20];
|
||||||
|
float math;
|
||||||
|
float physics;
|
||||||
|
float english;
|
||||||
|
float sum;
|
||||||
|
};
|
||||||
|
int main(){int i,j,k,m;
|
||||||
|
//初始化
|
||||||
|
struct Scoreb student1={10001,11,"Zhang",99.5,88.5,89.5,277.5};
|
||||||
|
struct Scoreb student2={10002,12,"Yang",77.9,56.5,87.5,221.9};
|
||||||
|
struct Scoreb student3={10003,11,"Liang",92.5,99.0,60.5,252};
|
||||||
|
struct Scoreb students[3] = {student1,student2,student3};
|
||||||
|
//修改信息
|
||||||
|
struct Scoreb schange;printf("依次输入学号班级姓名三科成绩:");
|
||||||
|
scanf("%d%d%s%f%f%f",&schange.schoolnumber,&schange.classnumber,&schange.name,&schange.math,&schange.physics,&schange.english);int c=schange.schoolnumber;
|
||||||
|
for(m=0;m<3;m++){
|
||||||
|
if(schange.schoolnumber==students[m].schoolnumber){
|
||||||
|
schange.sum = schange.math+schange.physics+schange.english;
|
||||||
|
students[m]=schange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//排序
|
||||||
|
for(j = 0 ; j < 3 ; j++)
|
||||||
|
for(k = 2; k > j;k--){
|
||||||
|
if(students[k].classnumber <students[k-1].classnumber){
|
||||||
|
struct Scoreb temp1 = students[k-1];
|
||||||
|
students[k-1] = students[k];
|
||||||
|
students[k] = temp1;
|
||||||
|
//按照班级号排名
|
||||||
|
}else if(students[k].classnumber == students[k-1].classnumber){
|
||||||
|
if(students[k].sum>students[k-1].sum){
|
||||||
|
struct Scoreb temp2 = students[k-1];
|
||||||
|
students[k-1] = students[k];
|
||||||
|
students[k] = temp2;
|
||||||
|
}//由高到低
|
||||||
|
//内嵌一个比较
|
||||||
|
//按照总成绩排名
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//输出
|
||||||
|
for(i = 0; i < 2 ; i++){
|
||||||
|
printf("%d %d %s %.1f %.1f %.1f\n",students[i].classnumber,students[i].schoolnumber,students[i].name,students[i].math,students[i].physics,students[i].english);
|
||||||
|
if(c==students[i].schoolnumber)printf("modified");if(students[0].classnumber==students[1].classnumber)
|
||||||
|
{
|
||||||
|
printf(" %d %s %.1f %.1f %.1f\n",students[1].schoolnumber,students[1].name,students[1].math,students[1].physics,students[1].english);break;}
|
||||||
|
}
|
||||||
|
printf("%d %d %s %.1f %.1f %.1f",students[2].classnumber,students[2].schoolnumber,students[2].name,students[2].math,students[2].physics,students[2].english);
|
||||||
|
if(c==students[2].schoolnumber)printf(" modified");
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue