#include #include #include #include #include #include using namespace std; int main() { FILE * in = fopen("game.in", "r"); while(1) { int n; fscanf(in, "%d", &n); char line[50]; fgets(line, sizeof(line), in); if (n == 0) return 0; int nteams = 0; map teams; map tnames; for (int i = 0; i < n; ++i ){ fscanf(in, "%s", line); tnames[nteams] = string(line); teams[string(line)] = nteams++; } map > rem; for(int i = 0; i < n-1; ++i) { fscanf(in, "%s", line); int a = teams[string(line)]; fscanf(in, "%s", line); int b = teams[string(line)]; rem[a].insert(b); rem[b].insert(a); } int round = 1; while(nteams) { printf("Round #%d\n", round++); int matches = nteams/2; vector played; played.assign(n, 0); for(int i = 0; i < n; ++i) if (rem[i].size()==0) played[i] = 1; while(matches) { for(int i = 0; i < n; ++i) { if (!played[i] && rem[i].size() == 1) { int t1 = i, t2 = *rem[i].begin(); if (played[t2] || played[t1]) continue ; printf("%s defeats %s\n", tnames[t2].c_str(), tnames[t1].c_str()); matches --; rem[t1].clear(); rem[t2].erase(t1); played[t1] = 1; played[t2] = 1; nteams --; if (nteams == 1) { printf("Winner: %s\n", tnames[t2].c_str()); nteams = 0; matches = 0; break; } } } } for(int i = 0; i < n && nteams; ++i) { if (!played[i]) printf("%s advances with wildcard\n", tnames[i].c_str()); } } printf("\n"); } }