-
Notifications
You must be signed in to change notification settings - Fork 0
/
218.c
67 lines (57 loc) · 1.38 KB
/
218.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
61
62
63
64
65
66
67
// http://www.bjfuacm.com/problem/218/
#include <stdio.h>
#include <stdlib.h>
#define OVERFLOW 11
struct Books;
typedef struct Books Book;
typedef struct Books* PtrToBook;
typedef PtrToBook List;
typedef PtrToBook Position;
struct Books {
char no[20];
char name[50];
float price;
struct Books* next;
};
void InitList(List* L) {
*L = (PtrToBook)calloc(1, sizeof(Book));
if (!*L) exit(OVERFLOW);
(*L)->next = NULL;
return;
}
int main() {
List L;
InitList(&L);
int count;
float max;
Position post, pre;
scanf("%d", &count);
for (int i = 0; i < count; i++) {
post = (PtrToBook)calloc(1, sizeof(Book));
if (!post) exit(OVERFLOW);
scanf("%s %s %f", post->no, post->name, &post->price);
if (i == 0) {
L->next = post;
max = post->price;
} else {
pre->next = post;
max = max < post->price ? post->price : max;
}
pre = post;
}
pre->next = NULL;
int cnt = 0;
Position p = L->next;
PtrToBook* ans = (PtrToBook*)calloc(count, sizeof(PtrToBook));
while (p) {
if (p->price == max) {
ans[cnt] = p;
cnt += 1;
}
p = p->next;
}
printf("%d\n", cnt);
for (int i = 0; i < cnt; i++) {
printf("%s %s %.2f\n", (*(ans + i))->no, (*(ans + i))->name, (*(ans + i))->price);
}
}