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
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "teams.h"
#include "common.h"
// ref(type) -> const ref to const data
// mut(type) -> const ref to mut data
// ptr(type) -> mut ref to mut data
void process(ref(char) line, unsigned idx, team obj)
{
unsigned s;
switch(idx) {
case 1:
set(team, obj, name, line);
break;
case 2:
set(team, obj, institution, line);
break;
case 3:
sscanf(line, "%u", &s);
set(team, obj, solved, s);
break;
case 4: // falls through
case 5: // falls through
case 6:
set(team, obj, member_name, idx - 3, line);
break;
default:
break;
}
}
int main()
{
unsigned num = 0, i = 0;
char line[255] = "";
ptr(team) teams;
getline(line, 255, stdin);
consume(line, 255, sscanf, "%u", &num);
teams = array(team, num);
if (teams == NULL) {
printf("Failed to reserve memory");
return 1;
}
for(i = 0; i < num; i++) {
teams[i] = new(team);
unsigned idx = 0;
while (idx ++ < 6) {
getline(line, 255, stdin);
consume(line, 255, process, idx, teams[i]);
}
}
team champion = ask(team, find_champion, NULL, teams, num);
ask(team, printf, champion);
while(num --) del(team, teams[num]);
free(teams);
return 0;
}
|