更新11948,重命名目录
This commit is contained in:
parent
7cd988db98
commit
b958a2ab18
|
@ -0,0 +1,60 @@
|
|||
#include <stdio.h>
|
||||
|
||||
struct student {
|
||||
int id, c;
|
||||
float x, y, z;
|
||||
float sum;
|
||||
} stu[233];
|
||||
|
||||
// 交换数据函数,也可以手写 c=a a=b b=c
|
||||
void swap(struct student* a, struct student* b) {
|
||||
struct student c;
|
||||
c = *a;
|
||||
*a = *b;
|
||||
*b = c;
|
||||
}
|
||||
|
||||
// 排序函数
|
||||
void sort() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4 - i - 1; j++) {
|
||||
if (stu[j].c > stu[j + 1].c || (stu[j].c == stu[j + 1].c && stu[j].sum > stu[j + 1].sum)) {
|
||||
swap(&stu[j], &stu[j + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
// scanf("%d,%d,%f,%f,%f", &stu[0].c, &stu[0].id, &stu[0].x, &stu[0].y, &stu[0].z);
|
||||
// scanf("%d,%d,%f,%f,%f", &stu[1].c, &stu[1].id, &stu[1].x, &stu[1].y, &stu[1].z);
|
||||
stu[0].c = 11;
|
||||
stu[0].id = 1001;
|
||||
stu[0].x = 92.5;
|
||||
stu[0].y = 82.5;
|
||||
stu[0].z = 96;
|
||||
|
||||
stu[1].c = 12;
|
||||
stu[1].id = 1002;
|
||||
stu[1].x = 82.5;
|
||||
stu[1].y = 87.5;
|
||||
stu[1].z = 93.5;
|
||||
|
||||
stu[2].c = 13;
|
||||
stu[2].id = 1003;
|
||||
stu[2].x = 97;
|
||||
stu[2].y = 84.5;
|
||||
stu[2].z = 88.5;
|
||||
|
||||
scanf("%d%d%f%f%f", &stu[3].id, &stu[3].c, &stu[3].x, &stu[3].y, &stu[3].z);
|
||||
stu[0].sum = stu[0].x + stu[0].y + stu[0].z;
|
||||
stu[1].sum = stu[1].x + stu[1].y + stu[1].z;
|
||||
stu[2].sum = stu[2].x + stu[2].y + stu[2].z;
|
||||
stu[3].sum = stu[3].x + stu[3].y + stu[3].z;
|
||||
|
||||
sort();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
printf("%d,%d,%.1f,%.1f,%.1f,%.1f\n", stu[i].id, stu[i].c, stu[i].x, stu[i].y, stu[i].z, stu[i].sum);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue