思路:模拟题。。不过有些麻烦。。
排名规则要处理好,特别是最后两条,前一个是场次少的排在前面,后面一个是要按字典序排列,不分大小写。。。我就是在这个地方WA了好多次。。。。无奈。。
#include<stdio.h> #include<string.h> #include<ctype.h> #include<stdlib.h> struct Team{ Team(){ point = 0; play = 0; win = 0; ties = 0; loss = 0; difference = 0; score = 0; against = 0; } int point; int play; int win; int ties; int loss; int difference; int score; int against; char name1[50]; char name2[50]; }; int cmp(void const *a, void const *b){ struct Team * c = (Team *)a; struct Team * d = (Team *)b; if (c -> point != d -> point) return d -> point - c -> point; if (c -> win != d -> win) return d -> win - c -> win; if (c -> difference != d -> difference) return d -> difference - c -> difference; if (c -> score != d -> score) return d -> score - c -> score; if (c -> play != d -> play) return c -> play - d -> play; return strcmp(c -> name2, d -> name2); } int main(){ int cas, n, m; char s[110]; scanf("%d", &cas); getchar(); while (cas--){ gets(s); scanf("%d", &n); Team team[1000]; getchar(); for(int i = 0; i < n; i++){ gets(team[i].name1); for(int j = 0; j < strlen(team[i].name1); j++) team[i].name2[j] = tolower(team[i].name1[j]); team[i].name2[strlen(team[i].name1)] = '\0'; } scanf("%d", &m); getchar(); while (m--){ int cnt = 0; char t1[50], t2[50], ch; while (ch = getchar(), ch != '#') t1[cnt++] = ch; t1[cnt] = '\0'; int a, b; scanf("%d", &a); getchar(); scanf("%d", &b); getchar(); gets(t2); for(int i = 0; i < n; i++){ if (strcmp(team[i].name1, t1) == 0){ if (a > b){ team[i].point += 3; team[i].difference += (a - b); team[i].win++; } else if (a == b){ team[i].point += 1; team[i].ties++; } else{ team[i].loss++; team[i].difference += (a - b); } team[i].play++; team[i].score += a; team[i].against += b; } if (strcmp(team[i].name1, t2) == 0){ if (b > a){ team[i].point += 3; team[i].difference += (b - a); team[i].win++; } else if (a == b){ team[i].point += 1; team[i].ties++; } else{ team[i].loss++; team[i].difference += (b - a); } team[i].play++; team[i].score += b; team[i].against += a; } } } qsort(team, n, sizeof(team[0]), cmp); puts(s); for(int i = 0; i < n; i++){ printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", i + 1, team[i].name1, team[i].point, team[i].play, team[i].win, team[i].ties, team[i].loss, team[i].difference, team[i].score, team[i].against); } if (cas) printf("\n"); } return 0; }