http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1135
有点繁琐,2A。
按照题目描述的排序即可。
# include <stdio.h> # include <ctype.h> # include <string.h> # include <stdlib.h> struct team{ char name[35]; char mname[35]; int played_games; int points; int wins; int ties; int loses; int goals; int goals_against; }; int n; char tournament_name[105]; int T; team a[35]; int G; int r[35]; char game[1005]; /* Most points earned. Most wins. Most goal difference (i.e. goals scored - goals against) Most goals scored. Less games played. Lexicographic order. */ int play(team *x, team *y) { if (x->points == y->points) { if (x->wins == y->wins) { int xgd = x->goals - x->goals_against; int ygd = y->goals - y->goals_against; if (xgd == ygd) { if (x->goals == y->goals) { if (x->played_games == y->played_games) { return strcmp(x->mname, y->mname); } else return x->played_games - y->played_games; } else return y->goals - x->goals; } else return ygd - xgd; } else return y->wins - x->wins; } else return y->points - x->points; } int icmp(const void *x, const void *y) { int xx = *(int *)x; int yy = *(int *)y; return play(&a[xx], &a[yy]); } int find(char *str) { for (int i = 1; i <= T; ++i) { if (strcmp(str, a[i].name) == 0) return i; } return 0; } int main() { char tmp[10]; scanf("%d", &n); gets(tmp); for (int i = 0; i < n; ++i) { if (i) putchar(' '); gets(tournament_name); puts(tournament_name); scanf("%d", &T); gets(tmp); for (int i = 1; i <= T; ++i) r[i] = i; for (int i = 1; i <= T; ++i) { gets(a[i].name); for (int j = 0; a[i].name[j]; ++j) { if (isalpha(a[i].name[j])) a[i].mname[j] = tolower(a[i].name[j]); else a[i].mname[j] = a[i].name[j]; } a[i].played_games = 0; a[i].points = 0; a[i].wins = a[i].ties = a[i].loses = 0; a[i].goals = 0; a[i].goals_against = 0; } scanf("%d", &G); gets(tmp); char buffer[35]; for (int k, i = 1; i <= G; ++i) { gets(game); for (k = 0; game[k] != '#'; ++k) buffer[k] = game[k]; buffer[k] = '