#include "stdio.h" #include "math.h" const char* fdata = "1 Willemkoen 5d Arnhem 35 7+ 6+ 2+ 4+ 3+ 5 164 164\n" "2 Rudi 5d Enschede 34 5+ 8+ 1- 10+ 6+ 4 164 129\n" "3 Yi 3d Amstelveen 33 8- 9+ 7+ 6+ 1- 3 163 96\n" "4 Sander 1k Harderwijk 33 13+ 5+ 10+ 1- 11+ 4 162 127\n" "5 Bert 3d Apeldoorn 33 2- 4- 16+ 7+ 9+ 3 161 94\n" "6 Bram 3d Utrecht 32 9+ 1- 8+ 3- 2- 2 166 64\n" "7 Alexander 1d ? 32 1- 11+ 3- 5- 14+ 2 162½ 61½\n" "8 Zhuo 2d Leiden 32 3+ 2- 6- 9- 12+ 2 162 64\n" "9 Mathijs 1d Utrecht 32 6- 3- 12+ 8+ 5- 2 161 63\n" "10 Jan 1d Apeldoorn 32 -- 12+ 4- 2- -- 1 158 31\n" "11 Karen 2k Utrecht 31 15+ 7- 13+ 16+ 4- 3 156½ 91½\n" "12 Sjoerd 1k Utrecht 31 16+ 10- 9- 14+ 8- 2 156½ 60½\n" "13 Henk 1k Amsterdam 31 4- 16- 11- 22+ 15+ 2 152½ 58½\n" "14 Kees 2k Apeldoorn 30½ -- 17+ 19+ 12- 7- 2 150 59\n" "15 Rob 2k Apeldoorn 30½ 11- -- 18+ 19+ 13- 2 149 59\n" "16 Araldo 1k Enschede 30 12- 13+ 5- 11- 17- 1 156 31\n" "17 Tijmen 3k Utrecht 30 18+ 14- 20- 27+ 16+ 3 147 87½ \n" "18 Rob 3k Almere 30 17- 22+ 15- 20+ 19+ 3 146½ 86\n" "19 Leon 3k Hilversum 29 22+ 27+ 14- 15- 18- 2 146½ 55½ \n" "20 Marinus 5k Harderwijk 29 33+ 23+ 17+ 18- 22+ 4 142 112\n" "21 Laurens 6k Harderwijk 29 31+ 29+ 32+ 28+ 23+ 5 135 135\n" "22 Wim 3k Harderwijk 28 19- 18- 24+ 13- 20- 1 147 28\n" "23 Jelger de 5k Almere 28 30+ 20- 25+ 24+ 21- 3 141 83\n" "24 Mirjam 5k Zeist 28 28+ 25+ 22- 23- 30+ 3 138 82\n" "25 Marieke 5k Arnhem 28 26+ 24- 23- 29+ 28+ 3 138 82\n" "26 Pepijn 5k Zeist 28 25- 30+ 28- 32+ 27+ 3 135½ 80½ \n" "27 Ton 4k Apeldoorn 27½ 29+ 19- -- 17- 26- 1 140 27\n" "28 Gerard 5k Zutphen 27 24- 33+ 26+ 21- 25- 2 139 54\n" "29 Rutger 4k Apeldoorn 27 27- 21- 31- 25- 33+ 1 137½ 26\n" "30 Hans 5k Arnhem 27 23- 26- 33+ 31+ 24- 2 137 53\n" "31 Gerrit 6k Almere 27 21- 34+ 29+ 30- 32+ 3 134 78\n" "32 Steven 5k Apeldoorn 26 -- -- 21- 26- 31- 0 134 0\n" "33 Wim 5k Barendrecht 26 20- 28- 30- 36+ 29- 1 133 23\n" "34 Ton 8k Enschede 25 36+ 31- 35- 38+ 37+ 3 120 68\n" "35 Michal 9k Almere 25 37+ 38- 34+ 39+ 36+ 4 114 92\n" "36 Jan-Willem 9k Almere 23 34- 39+ 38+ 33- 35- 2 118 42\n" "37 Roby 9k Amersfoort 23 35- -- 39+ -- 34- 1 112 20\n" "38 Liselot 11k Almere 22 39+ 35+ 36- 34- 41+ 3 112 64\n" "39 Rob 10k Betuwe 20 38- 36- 37- 35- 40- 0 114 0\n" "40 Martijn 15k Almere 19 44+ 41- 42+ 43+ 39+ 4 85 67\n" "41 Ciran 14k Zutphen 18 42- 40+ 43- 44+ 38- 2 90 35\n" "42 Frans 15k Enschede 17 41+ 43- 40- 46+ 45- 2 85 32\n" "43 Sanne 17k Almere 17 47+ 42+ 41+ 40- 48+ 4 79 60\n" "44 Milan 17k Den Haag 16 40- 46+ 45+ 41- 49+ 3 76 39\n" "45 Annabel 20k Enschede 14 49+ 47+ 44- 48+ 42+ 4 63 47\n" "46 Oskar 19k Almere 13 48+ 44- 49+ 42- 47- 2 66 21\n" "47 Donovan 19k ? 13 43- 45- 48- 49+ 46+ 2 64 22\n" "48 Titus 20k Enschede 11 46- 49- 47+ 45- 43- 1 65 13\n" "49 Sara 22k Enschede 9 45- 48+ 46- 47- 44- 1 63 11\n"; struct Player { int nr; char name[100]; int rank; struct { Player *player; int outcome; } games[5]; double old_r; double new_r; } players[100]; int nr_players = 0; int highest_rank = 0; int lowest_rank = 0; void parse_file(const char* fdata) { while (fdata != '\0') { players[nr_players].nr = nr_players + 1; // Skip number while (*fdata != '\t' && *fdata != '\0') fdata++; if (*fdata != '\t') return; fdata++; // Parse name int i; for (i = 0; *fdata != '\t' && *fdata != '\0'; fdata++) if (i < 99) players[nr_players].name[i++] = *fdata; players[nr_players].name[i++] = '\0'; if (*fdata != '\t') return; fdata++; // Parse rate int rank = 0; while ('0' <= *fdata && *fdata <= '9') { rank = 10*rank + *fdata - '0'; fdata++; } if (*fdata == 'k') rank = 1 - rank; while (*fdata != '\t' && *fdata != '\0') fdata++; if (*fdata != '\t') return; fdata++; players[nr_players].rank = rank; players[nr_players].old_r = 0; if (rank > highest_rank) highest_rank = rank; if (rank < lowest_rank) lowest_rank = rank; // Skip city while (*fdata != '\t' && *fdata != '\0') fdata++; if (*fdata != '\t') return; fdata++; // Skip number while (*fdata != '\t' && *fdata != '\0') fdata++; if (*fdata != '\t') return; fdata++; for (int round = 0; round < 5; round++) { // Process round int opponent = 0; for (; '0' <= *fdata && *fdata <= '9'; fdata++) opponent = opponent*10 + *fdata - '0'; if (opponent == 0) { players[nr_players].games[round].player = 0; } else { players[nr_players].games[round].player = &players[opponent-1]; players[nr_players].games[round].outcome = *fdata == '+'; } while (*fdata != '\t' && *fdata != '\0') fdata++; if (*fdata != '\t') return; fdata++; } // Skip till end of line while (*fdata != '\n' && *fdata != '\0') fdata++; if (*fdata == '\n') fdata++; nr_players++; } } int main(int argc, char *argv[]) { parse_file(fdata); double h_r; double l_r; for (int i = 0; i < 1000; i++) { for (int j = 0; j < nr_players; j++) { double sum_r = 0.0; int nr = 0; for (int k = 0; k < 5; k++) if (players[j].games[k].player != 0) { sum_r += players[j].games[k].player->old_r + (players[j].games[k].outcome ? 1 : -1); nr++; } players[j].new_r = (players[j].old_r + (sum_r / nr)) / 2; if (j == 0 || players[j].new_r > h_r) h_r = players[j].new_r; if (j == 0 || players[j].new_r < l_r) l_r = players[j].new_r; } for (int j = 0; j < nr_players; j++) players[j].old_r = players[j].new_r; } for (int j = 0; j < nr_players; j++) { players[j].old_r = players[j].new_r; double perc = (players[j].old_r - l_r) / (h_r - l_r); double rank = lowest_rank + (highest_rank - lowest_rank) * perc; printf("