#include #include #include #define HASH_SIZE 1024 struct tHashItem { tHashItem *next; int idx; ~tHashItem(); }; tHashItem::~tHashItem() { if (this->next != NULL) delete this->next; } struct tGame { int s1,s2,p; }; struct tTeam { char name[128]; int length; unsigned char games, won, tied, lost; short int s1, s2, points; int idx; }; int n,m; tHashItem htab[HASH_SIZE]; tTeam team[80]; tGame game[80][80]; void init(void) { int i,j; for (i=0; inext != NULL) act = act->next; p = new tHashItem; p->next = NULL; p->idx = idx; act->next = p; } } int hget(char *name) { unsigned int hash = makehash(name); if (htab[hash].next == NULL) return htab[hash].idx; else { tHashItem *act = &htab[hash]; do { if (strcmp(name, team[act->idx].name) == 0) return (act->idx); } while (act->next != NULL); } printf("!!!ERROR - item isnt in htab !!!\n"); return -1; } void hclean() { int i; for (i=0; i game[i][j].s2) { team[i].won++; team[j].lost++; team[i].points += 3; } else if (game[i][j].s1 < game[i][j].s2) { team[i].lost++; team[j].won++; team[j].points+=3; } else { team[i].tied++; team[j].tied++; team[i].points+=1; team[j].points+=1; } team[i].s1 += game[i][j].s1; team[i].s2 += game[i][j].s2; team[j].s1 += game[i][j].s2; team[j].s2 += game[i][j].s1; } } void separator(int x) { int i; char line[1024]; int p = 0; line[p++] = '+'; for (i = 0; i < x; i++) line[p++] = '-'; line[p++] = '+'; for (i = 0; i < n; i++) { line[p++] = '-'; line[p++] = '-'; line[p++] = '-'; line[p++] = '+'; } line[p] = '\0'; printf("%s\n", line); } int compare(const void *pb, const void *pa) { tTeam *a = (tTeam*)pa; tTeam *b = (tTeam*)pb; if (a->points > b->points) return 1; else if (a->points < b->points) return -1; else { if ((a->s1 - a->s2) > (b->s1 - b->s2)) return 1; if ((a->s1 - a->s2) < (b->s1 - b->s2)) return -1; else { if (a->s1 > b->s1) return 1; else if (a->s1 < b->s1) return -1; else { if (a->won > b->won) return 1; else if (a->won < b->won) return -1; else { if (a->idx > b->idx) return 1; else if (a->idx < b->idx) return -1; else return 0; } } } } return 0; } void print_tab1() { // !!! int i,j,maxname = 0; int p; char tmp[4]; char line[1024]; printf("RESULTS:\n"); for (i=0;i maxname) maxname = team[i].length; separator(maxname); p = 0; line[p++]='|'; for (i=0;i= 3) { line[p++] = team[i].name[0]; line[p++] = team[i].name[1]; line[p++] = team[i].name[2]; } else if (team[i].length == 2) { line[p++] = team[i].name[0]; line[p++] = team[i].name[1]; line[p++] = ' '; } else { line[p++] = team[i].name[0]; line[p++] = ' '; line[p++] = ' '; } line[p++] = '|'; } line[p] ='\0'; printf("%s\n", line); separator(maxname); for (i=0; i maxname) maxname = team[i].length; if (team[i].games > c2) c2 = team[i].games; if (team[i].won > c3) c3 = team[i].won; if (team[i].tied > c4) c4 = team[i].tied; if (team[i].lost > c5) c5 = team[i].lost; if (cif(team[i].s1)+cif(team[i].s2)+1 > a6) a6 = cif(team[i].s1)+cif(team[i].s2)+1; if (team[i].points > c8) c8 = team[i].points; } a1 = cif(c1); a2 = cif(c2); a3 = cif(c3); a4 = cif(c4); a5 = cif(c5); a8 = cif(c8); for (i=0; i %s (%d,%d)\n", t1, t2, s1, s2); idx1 = hget(t1); idx2 = hget(t2); game[idx1][idx2].s1 = s1; game[idx1][idx2].s2 = s2; game[idx1][idx2].p = 1; } calculate(); print_tab1(); printf("\n"); qsort(team, n, sizeof(tTeam), compare); print_tab2(); hclean(); } return 0; }