|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
// ѧ<><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD>Ľṹ<C4BD><E1B9B9>
|
|
|
|
|
struct Student {
|
|
|
|
|
int id;
|
|
|
|
|
int class;
|
|
|
|
|
float score1;
|
|
|
|
|
float score2;
|
|
|
|
|
float score3;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD>
|
|
|
|
|
void insertStudent(struct Student students[], int* numStudents, struct Student newStudent) {
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD>Ƿ<EFBFBD><C7B7>Ѵ<EFBFBD><D1B4><EFBFBD>
|
|
|
|
|
for (i = 0; i < *numStudents; i++) {
|
|
|
|
|
if (students[i].id == newStudent.id) {
|
|
|
|
|
printf("<EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>ŵ<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
students[*numStudents] = newStudent;
|
|
|
|
|
(*numStudents)++;
|
|
|
|
|
for (i = 0; i < *numStudents - 1; i++) {
|
|
|
|
|
for (j = 0; j < *numStudents - i - 1; j++) {
|
|
|
|
|
if (students[j].class > students[j + 1].class ||
|
|
|
|
|
(students[j].class == students[j + 1].class && students[j].score1 < students[j + 1].score1)) {
|
|
|
|
|
struct Student temp = students[j];
|
|
|
|
|
students[j] = students[j + 1];
|
|
|
|
|
students[j + 1] = temp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
|
|
|
|
for (i = 0; i < *numStudents; i++) {
|
|
|
|
|
printf("%d %d %.1f %.1f %.1f", students[i].id, students[i].class, students[i].score1, students[i].score2, students[i].score3);
|
|
|
|
|
if (i == *numStudents - 2) {
|
|
|
|
|
printf(" inserted");
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
// <20><><EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
struct Student students[3] = {
|
|
|
|
|
{10001, 11, 99.5, 88.5, 89.5},
|
|
|
|
|
{10002, 12, 77.9, 56.5, 87.5},
|
|
|
|
|
{10003, 11, 92.5, 99.0, 60.5}
|
|
|
|
|
};
|
|
|
|
|
int numStudents = 3;
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
struct Student newStudent;
|
|
|
|
|
scanf("%d %d %f %f %f", &newStudent.id, &newStudent.class, &newStudent.score1, &newStudent.score2, &newStudent.score3);
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
insertStudent(students, &numStudents, newStudent);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|