/* * Checker for Soccer League * r. anido * ACM2005 */ #include #include #include #define MAX_STR 15 #define MAX_MATCHES 1000 #define MAX_CLUBS MAX_MATCHES #define TRUE 1 #define FALSE 0 typedef struct aClub { char name[MAX_STR+1]; int points, diff, seen; } aClub; int nclubs; aClub clubs[MAX_CLUBS]; FILE *compet_out; void error(char *msg) { fprintf(stderr, "ERROR: %s\n", msg); exit(1); } int cmp(const void *a, const void *b) { if (((aClub*)a)->points==((aClub*)b)->points) return ((aClub*)b)->diff-((aClub*)a)->diff; else return ((aClub*)b)->points-((aClub*)a)->points; } void swap(aClub a, aClub b) { aClub tmp; tmp = a; a = b; b = tmp; } void insert(char *s) { strcpy(&clubs[nclubs++].name[0], s); } int lookup(char *s) { int i; for (i=0;iy) clubs[c1].points += 3; else if (xMAX_STR) error("club name too big"); c1 = lookup1(name); if (c1 >= nclubs) error("non-existent club name"); if (clubs[c1].seen==TRUE) error("club appears twice in table"); clubs[c1].seen=TRUE; if (points != clubs[j].points) error("wrong number of points"); if (clubs[c1].points != clubs[j].points) error("club appears out of place, number or points"); if (clubs[c1].diff != clubs[j].diff) error("club appears out of place, goal difference"); // clubs c1 and j have the same standing if (c1 != j) swap(clubs[c1],clubs[j]); j++; } if (fgets(line, sizeof(line), compet_out) == NULL) error("blank line in input file? should no happen!"); } if (fgets(line, sizeof(line), compet_out) != NULL) error("extra lines in output file"); fprintf(stderr,"Output is OK\n"); return 0; }