#include #include struct Student { char id[10]; int class_num; char name[20]; float score[3]; }; void sort_students(struct Student students[], int size) { int i, j; for (i = 0; i < size; i++) { for (j = i + 1; j < size; j++) { if (students[i].class_num > students[j].class_num || (students[i].class_num == students[j].class_num && students[i].score[0] + students[i].score[1] + students[i].score[2] < students[j].score[0] + students[j].score[1] + students[j].score[2])) { struct Student temp = students[i]; students[i] = students[j]; students[j] = temp; } } } } void print_student(struct Student student, int is_first) { if (is_first) { printf("%d %s %s %.1f %.1f %.1f ", student.class_num, student.id, student.name, student.score[0], student.score[1], student.score[2]); } else { printf(" %s %s %.1f %.1f %.1f\n", student.id, student.name, student.score[0], student.score[1], student.score[2]); } } int main() { struct Student students[3] = { {"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}} }; int size = sizeof(students) / sizeof(students[0]); sort_students(students, size); char search_id[10]; printf("请输入要修改的学生信息:\n"); scanf("%s %d %s %f %f %f", search_id, &students[0].class_num, students[0].name, &students[0].score[0], &students[0].score[1], &students[0].score[2]); int found = 0, i; for (i = 0; i < size; i++) { if (strcmp(students[i].id, search_id) == 0) { found = 1; students[i] = students[0]; break; } } if (found) { sort_students(students, size); printf("%d ", students[0].class_num); print_student(students[0], 1); printf("modified\n"); for (i = 1; i < size; i++) { if (students[i].class_num == students[i - 1].class_num) { print_student(students[i], 0); } else { printf("%d ", students[i].class_num); print_student(students[i], 1); } } } else { printf("未找到该学生信息\n"); } return 0; }