#include <stdio.h>

#include <stdlib.h>

#include <string.h>

typedef struct student {

char id[10];

char name[10];

int mark1;

int mark2;

int mark3;

    struct student *next;

}Student;


Student* creat_list(int num)

{

Student* p = (Student*)malloc(sizeof(Student));

Student* next_one=p;

p->next = NULL;

int i;

for (i = 1; i <= num; i++)

{

Student* q = (Student*)malloc(sizeof(Student));

q->next = NULL;

next_one->next = q;

next_one = next_one->next;

}

return p;

}



void data_enter(Student* p,int n)

{

Student *q = p;

for (int i = 1; i <= n; i++)

{

scanf("%s %s %d %d %d", q->id,q->name, &(q->mark1), &(q->mark2), &(q->mark3));

q = q->next;

}

}



void average_print(Student* p,int n)

{

int mark1_aver=0, mark2_aver=0, mark3_aver=0;

Student* q = p;

for (int i = 1; i <= n; i++)

{

mark1_aver += q->mark1;

mark2_aver += q->mark2;

mark3_aver += q->mark3;

q = q->next;

}

mark1_aver = mark1_aver/ n;

mark2_aver = mark2_aver/ n;

mark3_aver = mark3_aver / n;

printf("%d %d %d\n", mark1_aver, mark2_aver, mark3_aver);

}


void top_stu_find(Student* p, int n)

{

Student* q = p;

int max = 0;

int average = 0;

int flag=0;

int i;

for ( i = 1; i <= n; i++)

{

average = q->mark1 + q->mark2 + q->mark3;

if (max < average)

{

max = average;

flag = i;

}

q = q->next;

}

q = p;

for ( i = 1; i < flag; i++)

{

q = q->next;

}

printf("%s %s %d %d %d\n", q->id, q->name, q->mark1, q->mark2, q->mark3);

}


void link_free(Student* p, int n)

{

Student* q = p;

Student* next_one;

for (int i = 1; i <= n; i++)

{

next_one = q->next;

free(q);

q = next_one;

}

p = NULL;

}


int main(void)

{

int n;

scanf("%d", &n);

Student *p = creat_list(n);

data_enter(p, n);

average_print(p,n);

top_stu_find(p, n);

link_free(p, n);

return 0;

}


点赞(0)
 

0.0分

0 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论