一阶段结束考核题(链表的嵌套使用)

链表A,每个节点存放一个新的链表B1,B2,B3,B4,B5的头结点。
场景:一个年级,相当链表A
该年级5个班,每个班5个人,相当于链表B1–B5
做一个学生成绩管理系统
学生成绩有语文 数学 英语
功能: 录入成绩 找最三科总分的最高分 最低分 算出平均分

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct people
{char* name;int lesson;int number;int math;int chinese;int english;int all;struct people* next;
};struct class
{int class;struct people* firstpeople;struct class* next;
};struct class* insertfromclassbehind(struct class* classhead,struct class* classnewnode)
{struct class* p=NULL;p=classhead;if(classhead==NULL){classhead=classnewnode;return classhead;}struct people* insertfrompeoplebefore(struct people* peoplehead,struct people* peoplenewnode)
{if(peoplehead==NULL){peoplehead=peoplenewnode;}else{peoplenewnode->next=peoplehead;peoplehead=peoplenewnode;}return peoplehead;
}void linkPrintf(struct class* head)
{struct people* p=NULL;if(head==NULL){printf("打印失败,链表为空\n");}while(head!=NULL){p=head->firstpeople;while(p!=NULL){printf("姓名:%s\n",p->name);printf("班级:%d\n",p->lesson);printf("学号:%d\n",p->number);printf("数学:%d\n",p->math);printf("语文:%d\n",p->chinese);printf("英语:%d\n",p->english);printf("---------------------------------------------------------------------------------------------------\n");p=p->next;}head=head->next;}
}struct class* creatnewlink(struct class* classhead,struct people* peoplehead,int classall)
{struct class* classnewnode=NULL;struct people* peoplenewnode=NULL;while(classall){int number;classnewnode=(struct class*)malloc(sizeof(struct class));classnewnode->next=NULL;classnewnode->firstpeople=NULL;printf("请输入班级:\n");scanf("%d",&classnewnode->class);printf("请输入该班的人数:\n");scanf("%d",&number);while(number){peoplenewnode=(struct people*)malloc(sizeof(struct people));peoplenewnode->next=NULL;peoplenewnode->name=(char*)malloc(128);memset(peoplenewnode->name,'\0',128);peoplenewnode->lesson=classnewnode->class;printf("请输入姓名:\n");scanf("%s",peoplenewnode->name);
//                      printf("输入的是:%s\n",peoplenewnode->name);printf("请输入学号:\n");scanf("%d",&peoplenewnode->number);printf("请输入数学成绩:\n");scanf("%d",&peoplenewnode->math);printf("请输入语文成绩:\n");scanf("%d",&peoplenewnode->chinese);printf("请输入英语成绩:\n");scanf("%d",&peoplenewnode->english);peoplenewnode->all=peoplenewnode->english+peoplenewnode->math+peoplenewnode->chinese;peoplehead=insertfrompeoplebefore(peoplehead,peoplenewnode);number--;}classnewnode->firstpeople=peoplehead;peoplehead=NULL;//printf("****************************");classhead=insertfromclassbehind(classhead,classnewnode);classall--;}return classhead;
}void findmaxall(struct class*head)
{struct class* p=head;struct people* p2=p->firstpeople;struct people* max=NULL;max=p2;if(p==NULL){printf("参数不能为空!\n");}while(p!=NULL){p2=p->firstpeople;while(p2!=NULL){if(max->all<=p2->all){max=p2;}p2=p2->next;}p=p->next;}printf("---------------------------------------------------------------------------------------------------\n");printf("总分最高为:%d,姓名:%s,班级:%d,学号:%d\n",max->all,max->name,max->lesson,max->number);printf("---------------------------------------------------------------------------------------------------\n");
}void findminall(struct class*head)
{struct class* p=head;struct people* p2=p->firstpeople;struct people* min=NULL;min=p2;if(p==NULL){printf("参数不能为空!\n");}while(p!=NULL){p2=p->firstpeople;while(p2!=NULL){if(min->all>=p2->all){min=p2;}p2=p2->next;}p=p->next;}printf("总分最低为:%d,姓名:%s,班级:%d,学号:%d\n",min->all,min->name,min->lesson,min->number);printf("---------------------------------------------------------------------------------------------------\n");
}void findaverage(struct class* head)
{int mathall,chineseall,englishall,peopleall;mathall=chineseall=englishall=peopleall=0;struct people* p;if(head==NULL){printf("链表为空错误\n");}while(head!=NULL){p=head->firstpeople;while(p!=NULL){mathall=p->math+mathall;chineseall=p->chinese+chineseall;englishall=p->english+englishall;peopleall++;p=p->next;}head=head->next;}//printf("语文:%d,数学:%d,英语:%d\n",chineseall,mathall,englishall);printf("语文平均分:%f\n",(float)chineseall/peopleall);printf("数学平均分:%f\n",(float)mathall/peopleall);printf("英语平均分:%f\n",(float)englishall/peopleall);printf("---------------------------------------------------------------------------------------------------\n");
}
int main()
{struct class* classhead=NULL;struct people* peoplehead=NULL;int classall;printf("请输入班级总数:\n");scanf("%d",&classall);classhead=creatnewlink(classhead,peoplehead,classall);findmaxall(classhead);findminall(classhead);findaverage(classhead);//linkPrintf(classhead);return  0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/272241.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

RocketMQ带你快速入门

1. MQ介绍 ##1.1 为什么要用MQ 消息队列是一种“先进先出”的数据结构 转存失败重新上传取消 其应用场景主要包含以下3个方面 应用解耦 系统的耦合性越高&#xff0c;容错性就越低。以电商应用为例&#xff0c;用户创建订单后&#xff0c;如果耦合调用库存系统、物流系统、…

年过35岁的程序员都去哪了?一张图道尽老程序员们的花样出路

有人来&#xff0c;有人去。程序员何其多&#xff0c;想知道他们都去哪了吗?对于程序员的工作出路&#xff0c;小编有以下几点建议&#xff1a;20-27岁&#xff1a;技术积累阶段假设本科22岁毕业&#xff0c;那么工作的前5年对你来说是打基础的阶段。在这5年时间里面&#xff…

em,rem

em rem 相对单位: 也可用于设置padding line-height等em相对当前容器的默认字体设置比如,所有浏览器默认字体都是16px,body{ font-size:62.5%}以后即1em10px; 1.2em12px 在线转换tool: http://pxtoem.com/em(css2.0) rem(css3.0)rem相对于页根元素的字体大小&#xff0c;即 ht…

分布式、高并发、多线程,到底有什么区别?

当提起这三个词的时候&#xff0c;是不是很多人都认为分布式高并发多线程&#xff1f;当面试官问到高并发系统可以采用哪些手段来解决&#xff0c;或者被问到分布式系统如何解决一致性的问题&#xff0c;是不是一脸懵逼&#xff1f;确实&#xff0c;在一开始接触的时候&#xf…

linux文件编程(open、write、read、creat、lseek函数)

文件编程内容比较多&#xff0c;如文件系统原理及访问机制文件在内核中的管理机制&#xff0c;什么是文件信息节点iNode、文件共享、文件权限、各种用户对其权限等等。以下主要记录如何用代码操作文件&#xff0c;实现文件的创建、打开、编辑等自动化执行。 文件描述符介绍、其…

记忆化搜索,FatMouse and Cheese

题目链接&#xff1a;http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode1107 http://acm.hdu.edu.cn/showproblem.php?pid1078 1、从gird[0][0]出发&#xff0c;每次的方向搜索一下&#xff0c;每次步数搜索一下 for(i0; i<4; i) {for(j1; j<k; j){int tx…

九种跨域方式实现原理(完整版)

前言前后端数据交互经常会碰到请求跨域&#xff0c;什么是跨域&#xff0c;以及有哪几种跨域方式&#xff0c;这是本文要探讨的内容。一、什么是跨域&#xff1f;1.什么是同源策略及其限制内容&#xff1f;同源策略是一种约定&#xff0c;它是浏览器最核心也最基本的安全功能&a…

文件编程练习

自己实现linux CP指令 实现cp指令的思路&#xff1a; 打开要复制的原文件读原文件的内容到buf打开或者创建要粘贴的文件将buf里面的内容写到目标文件关闭两个文件 main 函数的标准原型&#xff1a; main 函数的标准原型应该是 int main(int argc, char *argv[]);argc 是命令…

java.lang.OutOfMemoryError: GC overhead limit exceeded

今天现场weblogic报java.lang.OutOfMemoryError: GC overhead limit exceeded&#xff0c;在metalink查了下&#xff0c;有明白解释&#xff0c;要设置一个JVM參数。只是因为当前weblogic内存设置为4G&#xff0c;所以设置參数的做法事实上并非解决这个问题之道。还是要分析web…

[翻译] Visual Studio 2019 RC版发布

今天&#xff0c;我们将分享 Visual Studio 2019 的发布候选版(RC 版) - 这是在 4 月 2 日的虚拟发布活动上正式发布之前的最后步骤之一。 您可以在 visualstudio.com/downloads 下载 RC 版。与往常一样&#xff0c;查看RC 版的发行说明以获取更多详细信息。发布候选版的说明在…

fread、fwrite、fopen函数的简单使用和open、read、write区别解析

这几个函数的区别&#xff1a;fread、fwrite、fopen和open、read、write区别解析 标准C库函数的简单使用 fopen函数原型&#xff1a; #include <stdio.h> FILE *fopen(const char *pathname, const char *mode);第一个参数是&#xff1a;要打开的文件路径 第二个参数是…

docker安装rocketmq你学会了吗

防火墙开通端口 9876 10911 9800 firewall-cmd --zonepublic --add-port9876/tcp --permanent firewall-cmd --zonepublic --add-port10911/tcp --permanent firewall-cmd --zonepublic --add-port9800/tcp --permanent firewall-cmd --reload 创建存储文件夹 mkdir -p /root…

程序员的编程能力与编程年龄

作者丨酷壳/陈皓&#xff0c; http://coolshell.cn/articles/10688.html程序员这个职业究竟可以干多少年&#xff0c;在中国这片神奇的土地上&#xff0c;很多人都说只能干到30岁&#xff0c;然后就需要转型&#xff0c;就像《程序员技术练级攻略》这篇文章很多人回复到这种玩…

Rocketmq集群架构图

集群架构图 集群特点

进程相关概念、C程序的空间分配

进程的定义&#xff1a; “进程”是操作系统的最基本、最重要的概念之一。但迄今为止对这一概念还没有一个确切的统一的描述。下面给出几种对进程的定义描述。 进程是程序的一次执行。进程是可以并行执行的计算。进程是一个程序与其使用的数据在处理机上顺序执行时发生的活动。…

(精)C#中TransactionScope的使用方法和原理

标签&#xff1a;.net transactionscope原创作品&#xff0c;允许转载&#xff0c;转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://cnn237111.blog.51cto.com/2359144/1271600在.net 1.1的时代&#xff0c;还没有TransactionScope…

一文搞定并发面试题

1、Object 的 wait()和notify() 方法下图为线程状态的图&#xff1a;Object 对象中的 wait()和notify()是用来实现实现等待 / 通知模式。其中等待状态和阻塞状态是不同的。等待状态的线程可以通过notify() 方法唤醒并继续执行&#xff0c;而阻塞状态的线程则是等待获取新的锁。…

fork、vfork、wait、waitpid

fork函数&#xff1a; 一个进程&#xff0c;包括代码、数据和分配给进程的资源。fork&#xff08;&#xff09;函数通过系统调用创建一个与原来进程几乎完全相同的进程&#xff0c;也就是两个进程可以做完全相同的事&#xff0c;但如果初始参数或者传入的变量不同&#xff0c;两…

java解析xml

<?xml version"1.0" encoding"UTF-8"?> <mimetype><default><mime-type>text/html</mime-type></default><mime-mapping><extension>zip</extension><mime-type>application/zip</mime-…