/* coder: ACboy date: 2010-2-27 result: AC description: UVa 10194 Football */ #include <iostream> #include <algorithm> #include <string> #include <vector> using namespace std; // 竞标赛的的次数 const int tournamentNameMAXN = 110; // 参加比赛的队伍数 const int teamMAXN = 40; // 比赛队伍的队名的长度 const int teamNameMAXN = 40; // 球队结构体 struct Team { // 队名 string teamName; // 积分 int point; // 获胜场次 int wins; // 失败场次 int loss; // 平局场次 int tie; // 进球数 int scored; // 丢球数 int against; Team(string t = "") : teamName(t), point(), wins(), loss(), tie(), scored(), against() {} }; bool teamNameCmp(const Team & a, const Team & b) { return a.teamName < b.teamName; } // 二分查找 int binary_search(Team teams[], string teamName, int count) { int begin = 0; int end = count - 1; int mid; int pos = -1; while (begin <= end) { mid = (begin + end) / 2; if (teams[mid].teamName == teamName) {pos = mid; break;} else if (teams[mid].teamName > teamName) { end = mid - 1; } else { begin = mid + 1; } } return pos; } // 球队排序规则 bool standingCmp(const Team & a, const Team & b) { if (a.point != b.point) { return a.point > b.point; } else if (a.wins != b.wins) { return a.wins > b.wins; } else if (a.scored - a.against != b.scored - b.against) { return a.scored - a.against > b.scored - b.against; } else if (a.scored != b.scored) { return a.scored > b.scored; } else if (a.wins + a.loss + a.tie != b.wins + b.loss + b.tie) { return a.wins + a.loss + a.tie < b.wins + b.loss + b.tie; } else { return strcasecmp(a.teamName.c_str(), b.teamName.c_str()) < 0; } } int main() { int i, j; int N, G, T; #ifndef ONLINE_JUDGE freopen("10194.txt", "r", stdin); #endif scanf("%d/n", &N); while (N--) { Team teams[teamMAXN]; char tournamemtName[tournamentNameMAXN]; gets(tournamemtName); printf("%s/n", tournamemtName); scanf("%d/n", &T); for (i = 0; i < T; i++) { string teamName; getline(cin, teamName); teams[i].teamName = teamName; } sort(teams, teams + T, teamNameCmp); scanf("%d/n", &G); for (i = 0; i < G; i++) { char tp[100]; gets(tp); int goal1; int goal2; char team1[teamNameMAXN]; char team2[teamNameMAXN]; sscanf(tp, "%[^#]#%d@%d#%[^#]",team1, &goal1, &goal2, team2); string strTeam1= string(team1); string strTeam2 = string(team2); int team1Pos = binary_search(teams, strTeam1, T); int team2Pos = binary_search(teams, strTeam2, T); teams[team1Pos].scored += goal1; teams[team1Pos].against += goal2; teams[team2Pos].scored += goal2; teams[team2Pos].against += goal1; if (goal1 > goal2) { teams[team1Pos].wins++; teams[team2Pos].loss++; teams[team1Pos].point += 3; } else if (goal1 < goal2) { teams[team1Pos].loss++; teams[team2Pos].wins++; teams[team2Pos].point += 3; } else { teams[team1Pos].tie++; teams[team2Pos].tie++; teams[team1Pos].point += 1; teams[team2Pos].point += 1; } } sort(teams, teams + T, standingCmp); for (j = 0; j < T; j++) { printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)/n", j + 1, teams[j].teamName.c_str(), teams[j].point, teams[j].wins + teams[j].loss + teams[j].tie, teams[j].wins, teams[j].tie, teams[j].loss, teams[j].scored - teams[j].against, teams[j].scored, teams[j].against); } if (N > 0) printf("/n"); } return 0; }