You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123xj/6c8c9d0552e7613b0bb0108013c...

91 lines
2.5 KiB

#include <stdio.h>
#include <string.h>
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD><E1B9B9>
struct Student {
char studentID[10];
int classs;
char name[20];
float score1;
float score2;
float score3;
};
// <20><>ʼ<EFBFBD><CABC>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
struct Student students[] = {
{"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}
};
// ѧ<><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>
int length = sizeof(students) / sizeof(students[0]);
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
void deleteStudent(char* input) {
int i, j;
int found = 0; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ҵ<EFBFBD><D2B5><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
for (i = 0; i < length; i++) {
// <20>ж<EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ƥ<EFBFBD><C6A5>
if (strcmp(students[i].studentID, input) == 0 || strcmp(students[i].name, input) == 0) {
found = 1; // <20>ҵ<EFBFBD><D2B5>˴<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ǰ<EFBFBD>ƶ<EFBFBD>
for (j = i; j < length - 1; j++) {
students[j] = students[j + 1];
}
length--; // ѧ<><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>ȼ<EFBFBD>һ
break;
}
}
}
// <20><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
void printStudents() {
int i;
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
for (i = 0; i < length - 1; i++) {
int minIndex = i;
int j;
for (j = i + 1; j < length; j++) {
// <20><><EFBFBD><EFBFBD><E0BCB6>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<CDAC><EFBFBD>ڰ<EFBFBD><DAB0>ܳɼ<DCB3><C9BC>Ӵ<EFBFBD><D3B4><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>
if (students[j].classs < students[minIndex].classs ||
(students[j].classs == students[minIndex].classs &&
students[j].score1 + students[j].score2 + students[j].score3 >
students[minIndex].score1 + students[minIndex].score2 + students[minIndex].score3)) {
minIndex = j;
}
}
// <20><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
struct Student temp = students[i];
students[i] = students[minIndex];
students[minIndex] = temp;
}
// <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ
for (i = 0; i < length; i++) {
printf("\n%s %d %s %.1f %.1f %.1f\n", students[i].studentID, students[i].classs, students[i].name, students[i].score1, students[i].score2, students[i].score3);
}
}
int main() {
char input[20];
// <20><>ʾ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><C5BB><EFBFBD><EFBFBD><EFBFBD>
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>Ż<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%s", input);
printf("Are you sure(yes/no)?\n");
char c;
scanf(" %c", &c);
if (c=='y'){
deleteStudent(input);
printStudents();}
else if(c=='n')
printStudents();
return 0;
}