一階段結束考核題(鏈表的嵌套使用)

鏈表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.pswp.cn/news/272241.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/272241.shtml
英文地址,請注明出處:http://en.pswp.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-…