#include #include #include #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(obj, name, line); break; case 2: Set(obj, institution, line); break; case 3: sscanf(line, "%u", &s); Set(obj, solved, s); break; case 4: // falls through case 5: // falls through case 6: Set(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 = Call(dref(teams), find_champion, teams, num); Call(champion, printf); while(num --) Del(team, teams[num]); free(teams); return 0; }