1

40 阅读1分钟

#include <stdio.h>#include <string.h>typedef struct { char name[50]; float score; int rank;} Student;void printStudents(Student students[], int n) { for (int i = 0; i < n; i++) { printf("%d %s %.2f\n", students[i].rank, students[i].name, students[i].score); }}void sortStudents(Student students[], int n) { for (int i = 0; i < n - 1; i++) { int minIndex = i; for (int j = i + 1; j < n; j++) { if (students[j].score > students[minIndex].score) { minIndex = j; } } Student temp = students[minIndex]; students[minIndex] = students[i]; students[i] = temp; students[i].rank = i + 1; } students[n - 1].rank = n;}int main() { int n = 0; Student students[100]; // 读取学生信息 while (1) { scanf("%s%f", students[n].name, &students[n].score); if (strcmp(students[n].name, "0") == 0 && students[n].score == 0.0) { break; }