-
Notifications
You must be signed in to change notification settings - Fork 100
/
1095.c
94 lines (86 loc) · 2.04 KB
/
1095.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct {
char string[14];
char level[2]; /* use 2-char array to avoid reading problems */
int room;
int date;
int id;
int score;
} Info;
int cmp(const void *a, const void *b)
{
Info *ipa = (Info*)a;
Info *ipb = (Info*)b;
if (ipa->score != ipb->score)
return ipb->score - ipa->score;
return strcmp(ipa->string, ipb->string);
}
int main()
{
int N, M, type, NAflag;
Info info[10000];
scanf("%d %d", &N, &M);
for (int i = 0; i < N; i++) {
scanf("%s %d", info[i].string, &info[i].score);
sscanf(info[i].string, "%1s%3d%6d%3d",
info[i].level,
&info[i].room,
&info[i].date,
&info[i].id);
}
qsort(info, N, sizeof(Info), cmp);
for (int i = 0; i < M; i++) {
NAflag = 1;
scanf("%d", &type);
if (type == 1) {
char level[2];
scanf("%1s", level);
printf("Case %d: %d %c\n", i + 1, type, level[0]);
for (int j = 0; j < N; j++)
if (info[j].level[0] == level[0]) {
NAflag = 0;
printf("%c%03d%06d%03d %d\n", info[j].level[0],
info[j].room, info[j].date,
info[j].id, info[j].score);
}
if (NAflag)
printf("NA\n");
} else if (type == 2) {
int room, sum = 0, count = 0;
scanf("%d", &room);
printf("Case %d: %d %d\n", i + 1, type, room);
for (int j = 0; j < N; j++)
if (info[j].room == room) {
NAflag = 0;
count++;
sum += info[j].score;
}
if (NAflag)
printf("NA\n");
else
printf("%d %d\n", count, sum);
} else if (type == 3) {
int date, max = 0, rooms[1000] = {0};
scanf("%d", &date);
printf("Case %d: %d %06d\n", i + 1, type, date);
for (int j = 0; j < N; j++)
if (info[j].date == date) {
NAflag = 0;
rooms[info[j].room]++;
if (max < rooms[info[j].room])
max = rooms[info[j].room];
}
if (NAflag) {
printf("NA\n");
} else { /* print by count dec and room number inc */
for (int c = max; c > 0; c--)
for (int r = 101; r < 1000; r++)
if (rooms[r] == c)
printf("%d %d\n", r, c);
}
}
}
return 0;
}