Document directory
- Lab questions (10 questions in total, 4th questions)
Lab questions (10 questions in total, 4th questions)
Title: |
Student Information Management |
Time limit: |
1000 MS |
Memory limit: |
20000 K |
Total time limit: |
3000 MS |
Description: |
Use a chained storage structure to manage student information in a class. Design the program to find the average score of each person and sort the average score by the descending order to output the student records. |
Input: |
N Personnel Record 1 (Format: Student ID name Score 1 score 2 score 3) Personnel record 2 |
Output: |
Personnel Record X 1 Personnel Record Y 2 ... Personnel Record Z N |
Input example: |
3 1 sun Lili 76 78 89 2 Zhang Ziyi 72 56 67 3 Andy Lau 56 84 90 |
Output example: |
1 sun Lili 76 78 89 81.00 1 3 Andy Lau 56 84 90 76.67 2 2 Zhang Ziyi 72 56 67 65.00 3 |
Tip: |
|
Source: |
View code
1 #include<stdio.h>
2 #include<stdlib.h>
3
4 #define ElemType int
5 typedef struct Student
6 {
7 int num;
8 char name[10];
9 float score1;
10 float score2;
11 float score3;
12 float average;
13 struct Student *next;
14 } student,*stu;
15
16 void CreatList(stu L,ElemType n)
17 {
18 stu p1;
19 while(n>0)
20 {
21 p1=(stu)malloc(sizeof(student));
22 scanf("%d",&p1->num);
23 scanf("%s",p1->name);
24 scanf("%f",&p1->score1);
25 scanf("%f",&p1->score2);
26 scanf("%f",&p1->score3);
27 L->next=p1;
28 L=p1;
29 n--;
30 }
31 L->next=NULL;
32 }
33
34 void AverageScore(stu L)
35 {
36 stu p;
37 p=L->next;
38 while(p)
39 {
40 p->average=((p->score1)+(p->score2)+(p->score3))/3;
41 p=p->next;
42 }
43
44 }
45
46 void List_Sort(stu L)
47 {
48 stu p,q,r,s,l;
49 l=L;
50 p=L->next;
51 while(p)
52 {
53 r=p;
54 q=p->next;
55 while(q)
56 {
57 if(r->average<q->average)
58 r=q;
59 q=q->next;
60 }
61 s=p;
62 if(s->average==r->average && s->num==r->num)
63 {
64 p=p->next;
65 l->next=r;
66 l=r;
67 }
68 else
69 {
70 while(s->next->num!=r->num)
71 s=s->next;
72 s->next=r->next;
73 l->next=r;
74 l=r;
75 }
76 }
77 l->next=NULL;
78 }
79
80 void TraverseList(stu L,ElemType n)
81 {
82 ElemType i=0;
83 stu p;
84 p=L->next;
85 while(p)
86 {
87 i++;
88 if(i==n && n>10)
89 printf("%d %s %.2f %.2f %.2f %.2f %d\n",p->num,p->name,p->score1,p->score2,p->score3,p->average,i);
90 else printf("%d %s %.2f %.2f %.2f %.2f %d\n",p->num,p->name,p->score1,p->score2,p->score3,p->average,i);
91 p=p->next;
92 }
93 }
94 int main()
95 {
96 ElemType n;
97 stu L;
98 L=(stu)malloc(sizeof(student));
99 L->next=NULL;
100 scanf("%d",&n);
101 CreatList(L,n);
102 AverageScore(L);
103 List_Sort(L);
104 TraverseList(L,n);
105 return 0;
106 }