diff --git a/1/11943.c b/homework/11943.c similarity index 100% rename from 1/11943.c rename to homework/11943.c diff --git a/1/11944.c b/homework/11944.c similarity index 100% rename from 1/11944.c rename to homework/11944.c diff --git a/1/11945.c b/homework/11945.c similarity index 100% rename from 1/11945.c rename to homework/11945.c diff --git a/1/11946.c b/homework/11946.c similarity index 100% rename from 1/11946.c rename to homework/11946.c diff --git a/1/11947.c b/homework/11947.c similarity index 100% rename from 1/11947.c rename to homework/11947.c diff --git a/homework/11948.c b/homework/11948.c new file mode 100644 index 0000000..7888700 --- /dev/null +++ b/homework/11948.c @@ -0,0 +1,60 @@ +#include + +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; +} \ No newline at end of file diff --git a/1/12625.c b/homework/12625.c similarity index 100% rename from 1/12625.c rename to homework/12625.c diff --git a/1/12626.c b/homework/12626.c similarity index 100% rename from 1/12626.c rename to homework/12626.c