-
Notifications
You must be signed in to change notification settings - Fork 0
/
208.c
58 lines (48 loc) · 1.18 KB
/
208.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
// http://www.bjfuacm.com/problem/208/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSIZE 10000
#define OVERFLOW 11
typedef struct Books Book;
typedef struct SqLists SqList;
struct Books {
char no[20];
char name[50];
float price;
};
struct SqLists {
struct Books* elem;
int len;
};
void InitList(SqList* L) {
L->elem = (Book *)calloc(MAXSIZE, sizeof(Book));
if (!L->elem) exit(OVERFLOW);
L->len = 0;
return;
}
int main() {
SqList L;
InitList(&L);
int amount;
scanf("%d", &amount);
double max = 0.0;
for (int i = 0; i < amount; i++) {
scanf("%s %s %f", L.elem[i].no, L.elem[i].name, &L.elem[i].price);
max = max < L.elem[i].price ? L.elem[i].price : max;
L.len += 1;
}
int* ans = (int *)malloc(amount * sizeof(int));
int count = 0;
// memset(ans, 0, sizeof(int));
for (int i = 0; i < amount; i++) {
if (L.elem[i].price == max) {
ans[count] = i;
count += 1;
}
}
printf("%d\n", count);
for (int i = 0; i < count; i++) {
printf("%s %s %.2f\n", L.elem[ans[i]].no, L.elem[ans[i]].name, L.elem[ans[i]].price);
}
}