-
Notifications
You must be signed in to change notification settings - Fork 0
/
1004. 成绩排名 (20)-链表.c
60 lines (56 loc) · 997 Bytes
/
1004. 成绩排名 (20)-链表.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct stu_node{
char num[20];
char name[20];
int score;
struct stu_node* next;
};
typedef struct stu_node* Position;
typedef struct stu_node* List;
int main()
{
List L=(List)malloc(sizeof(struct stu_node));
L->score=0;
L->next=NULL;
List p=L,tmp;
char num[20];
int score;
char name[20];
int n;
scanf("%d",&n);
getchar();
int i,min=101,max=-1;
for(i=0;i<n;i++){
scanf("%s %s %d",name,num,&score);
getchar();
if(score>max)
max=score;
if(score<min)
min=score;
tmp=(List)malloc(sizeof(struct stu_node));//对于一组数据,应该重新要一块空间!!!!
strcpy(tmp->name,name);
tmp->score=score;
strcpy(tmp->num,num);
tmp->next=NULL;
p->next=tmp;
p=tmp;
}
L=L->next;
tmp=L;
while(tmp){
if(tmp->score==max){
printf("%s %s\n",tmp->name,tmp->num);
}
tmp=tmp->next;
}
tmp=L;
while(tmp){
if(tmp->score==min){
printf("%s %s\n",tmp->name,tmp->num);
}
tmp=tmp->next;
}
return 0;
}