diff --git a/10a21d526864aa291186ad1e11cb2e8f_ac52ed117b4936b1258f8cb3642effb4_8.c b/10a21d526864aa291186ad1e11cb2e8f_ac52ed117b4936b1258f8cb3642effb4_8.c new file mode 100644 index 0000000..5fdc03f --- /dev/null +++ b/10a21d526864aa291186ad1e11cb2e8f_ac52ed117b4936b1258f8cb3642effb4_8.c @@ -0,0 +1,56 @@ +#include +int main(){int i,m,n,v; + int j; + int k; +// 定义结构体用于储存信息 +// 定义一个结构体数组,并初始化结构体 + struct student{ + int stuNum; + int classNum; + float score[3]; + float sum; + }stu[4]={{ + 10001,11,99.5,88.5,89.5 + },{ + 10002,12,77.9,56.5,87.5 + },{ + 10003,11,92.5,99.0,60.5 + } + }; +// 输入第四个学生的信息 ,并求得其总分 +printf("学号:"); + scanf("%d", &stu[3].stuNum);k=stu[3].stuNum;for(i=0;i<3;i++){ + if(k==stu[i].stuNum){ printf("学号已存在,信息为\n %d %d %.1f %.1f %.1f", stu[i].stuNum, stu[i].classNum, stu[i].score[0], stu[i].score[1], stu[i].score[2]); + return 0;} + } +printf("班级:"); + scanf("%d", &stu[3].classNum); +printf("三科成绩:"); + for(m=0;m<3;m++){ + scanf("%f", &stu[3].score[m]); + stu[3].sum+=stu[3].score[m]; + } +// 利用插入排序进行排序 + for(n=1;n<4;n++){ + for(j=n;j>0;j--){ +// 先对班级号排序,再对总分排序 + if(stu[j].classNumstu[j-1].sum){ + struct student temp = stu[j]; + stu[j] = stu[j-1]; + stu[j-1] = temp; + } + } + } +// 将排序后的结果输出 + for(v=0;v<4;v++){ + printf("\n%d %d %.1f %.1f %.1f", stu[v].stuNum, stu[v].classNum, stu[v].score[0], stu[v].score[1], stu[v].score[2]); + + if(stu[v].stuNum==k)printf(" inserted"); + } + return 0; +}