C 语言链式存储校运会 100 米初赛管理程序:功能实现与优化建议
以下是一个使用 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. 增加对文件的读写操作,以便保存和读取数据。 ######[AI写代码神器 | 1127点数解答 | 2024-12-28 12:54:28]
- Python 实现简易密码设置系统:多种功能交互与安全要点揭秘(字节豆包 | 286点数解答 | 2025-03-28 10:43:21)379
- C语言实现多功能密码设置系统:含代码及安全注意要点(字节豆包 | 414点数解答 | 2025-03-28 10:43:55)366
- C 语言实现:超简单密码设置系统,含代码与注意要点!(字节豆包 | 519点数解答 | 2025-03-28 12:42:02)403
- C语言实现密码管理系统:含功能代码与安全注意事项(字节豆包 | 409点数解答 | 2025-04-05 18:09:56)351
- C语言实现多功能密码系统:初始化、确认、设置、显示、重置与退出(字节豆包 | 454点数解答 | 2025-04-05 18:48:42)352
- C语言实现密码管理系统:含初始化、确认、设置、显示、重置及退出功能(字节豆包 | 413点数解答 | 2025-04-06 15:37:16)298
- C 语言实现密码管理系统:含初始化、确认、设置、显示、重置及退出功能(字节豆包 | 403点数解答 | 2025-04-06 15:37:54)310
- 补全代码:将数组所有元素赋值为 100 并输出(字节豆包 | 164点数解答 | 2025-11-01 19:14:57)112
- C++实现图像模糊化处理:含代码、解释与复杂度分析(字节豆包 | 670点数解答 | 2025-11-10 18:55:33)127
- C++实现图像像素灰度值模糊化处理:输入输出全解析(字节豆包 | 655点数解答 | 2025-12-01 14:24:01)101
- Python 实现图像模糊化:输入像素值,输出处理后图像(附代码及详细解释)(字节豆包 | 555点数解答 | 2025-12-09 12:22:26)103
- Java实现有序集合合并与交集算法(顺序表+单链表)(百度文心 | 1247点数解答 | 2026-03-25 10:35:22)26