|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h> // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> qsort <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
|
|
|
|
#include <string.h> // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
|
|
|
|
|
|
|
|
|
// ѧ<><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD>Ľṹ<C4BD><E1B9B9>
|
|
|
|
|
struct Student {
|
|
|
|
|
int student_id;
|
|
|
|
|
int class_id;
|
|
|
|
|
char name[50];
|
|
|
|
|
float score1;
|
|
|
|
|
float score2;
|
|
|
|
|
float score3;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// <20>ȽϺ<C8BD><CFBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int compareStudents(const void *a, const void *b) {
|
|
|
|
|
struct Student *student1 = (struct Student *)a;
|
|
|
|
|
struct Student *student2 = (struct Student *)b;
|
|
|
|
|
|
|
|
|
|
if (student1->class_id != student2->class_id) {
|
|
|
|
|
return student1->class_id - student2->class_id;
|
|
|
|
|
} else {
|
|
|
|
|
float total_score1 = student1->score1 + student1->score2 + student1->score3;
|
|
|
|
|
float total_score2 = student2->score1 + student2->score2 + student2->score3;
|
|
|
|
|
return total_score2 - total_score1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
struct Student students[100];
|
|
|
|
|
int num_students = 3; // <20><>ʼ<EFBFBD><CABC>3<EFBFBD><33>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
|
|
|
|
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
students[0] = (struct Student){10001, 11, "Zhang", 99.5, 88.5, 89.5};
|
|
|
|
|
students[1] = (struct Student){10002, 12, "Yang", 77.9, 56.5, 87.5};
|
|
|
|
|
students[2] = (struct Student){10003, 11, "Liang", 92.5, 99.0, 60.5};
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
qsort(students, num_students, sizeof(struct Student), compareStudents);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
char search[50];
|
|
|
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
scanf("%s", search);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>˳<EFBFBD><CBB3><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int i,j,found = 0;
|
|
|
|
|
for (i = 0; i < num_students; i++) {
|
|
|
|
|
if (strcmp(search, students[i].name) == 0 || atoi(search) == students[i].student_id) {
|
|
|
|
|
found = 1;
|
|
|
|
|
for (j = i; j < num_students - 1; j++) {
|
|
|
|
|
students[j] = students[j + 1];
|
|
|
|
|
}
|
|
|
|
|
num_students--;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
|
printf("<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
|
|
|
|
|
for (i = 0; i < num_students; i++) {
|
|
|
|
|
printf("%d %d %s %.1f %.1f %.1f\n", students[i].student_id, students[i].class_id, students[i].name, students[i].score1, students[i].score2, students[i].score3);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
for (i = 0; i < num_students; i++) {
|
|
|
|
|
printf("%d %d %s %.1f %.1f %.1f\n", students[i].student_id, students[i].class_id, students[i].name, students[i].score1, students[i].score2, students[i].score3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ѯ<><D1AF><EFBFBD>û<EFBFBD><C3BB>Ƿ<EFBFBD>ȷ<EFBFBD><C8B7>ɾ<EFBFBD><C9BE>
|
|
|
|
|
char confirm[3];
|
|
|
|
|
printf("Are you sure(yes/no)? ");
|
|
|
|
|
scanf("%s", confirm);
|
|
|
|
|
if (strcmp(confirm, "n") == 0) {
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD> "no"<22><><EFBFBD>ٴ<EFBFBD><D9B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
printf("%d %d %s %.1f %.1f %.1f\n", students[i].student_id, students[i].class_id, students[i].name, students[i].score1, students[i].score2, students[i].score3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|