以下是一个使用 C 语言实现基于链式存储结构的校运会径赛管理程序的示例代码: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> // 选手信息结构体 typedef struct Athlete { char name[50]; int number; int group; float score; struct Athlete *next; } Athlete; // 创建新选手节点 Athlete* createAthlete(char name[], int number) { Athlete* newAthlete = (Athlete*)malloc(sizeof(Athlete)); strcpy(newAthlete->name, name); newAthlete->number = number; newAthlete->group = -1; newAthlete->score = 0.0; newAthlete->next = NULL; return newAthlete; } // 插入选手节点到链表 void insertAthlete(Athlete head, Athlete* newAthlete) { if (*head == NULL) { *head = newAthlete; } else { Athlete* current = *head; while (current->next!= NULL) { current = current->next; } current->next = newAthlete; } } // 根据姓名或编号删除选手节点 void deleteAthlete(Athlete head, char name[], int number) { Athlete* current = *head; Athlete* prev = NULL; while (current!= NULL) { if ((strcmp(current->name, name) == 0) || (current->number == number)) { if (prev == NULL) { *head = current->next; } else { prev->next = current->next; } free(current); return; } prev = current; current = current->next; } } // 抽签分组 void drawLots(Athlete* head, int groupSize) { int count = 1; Athlete* current = head; while (current!= NULL) { current->group = (count - 1) / groupSize + 1; count++; current = current->next; } } // 打印链表中的选手信息 void printAthletes(Athlete* head) { Athlete* current = head; printf("姓名\t编号\t组号\t成绩\n"); while (current!= NULL) { printf("%s\t%d\t%d\t%.2f\n", current->name, current->number, current->group, current->score); current = current->next; } } // 主函数 int main() { Athlete* head = NULL; int choice; char name[50]; int number; do { printf("\n1. 录入选手信息\n"); printf("2. 删除选手信息\n"); printf("3. 抽签分组\n"); printf("4. 打印选手信息\n"); printf("5. 退出\n"); printf("请选择: "); scanf("%d", &choice); switch (choice) { case 1: printf("请输入选手姓名: "); scanf("%s", name); printf("请输入选手编号: "); scanf("%d", &number); Athlete* newAthlete = createAthlete(name, number); insertAthlete(&head, newAthlete); break; case 2: printf("请输入要删除选手的姓名或编号: "); scanf("%s", name); if (atoi(name)!= 0) { number = atoi(name); } deleteAthlete(&head, name, number); break; case 3: int groupSize; printf("请输入每组人数: "); scanf("%d", &groupSize); drawLots(head, groupSize); break; case 4: printAthletes(head); break; case 5: break; default: printf("无效的选择,请重新输入\n"); } } while (choice!= 5); Athlete* current = head; while (current!= NULL) { Athlete* temp = current; current = current->next; free(temp); } return 0; } ``` 以下是三个可行的改进建议: 1. 增加对输入数据的合法性检查,例如姓名和编号的格式。 2. 优化链表的遍历和操作,提高程序的效率。 3. 增加对文件的读写操作,以便保存和读取数据。 [2024-12-28 12:54:28 | AI写代码神器 | 1127点数解答]