Nothing worthy to mention.
Code:
- /*************************************************************************
- * Copyright (C) 2008 by liukaipeng *
- * liukaipeng at gmail dot com *
- *************************************************************************/
- /* @JUDGE_ID 00000 10194 C++ "Football (aka Soccer)" */
- #include <algorithm>
- #include <cstdio>
- #include <cstring>
- #include <deque>
- #include <fstream>
- #include <iostream>
- #include <list>
- #include <map>
- #include <queue>
- #include <set>
- #include <stack>
- #include <string>
- #include <vector>
- using namespace std;
- int const teamcount = 30;
- int const gamecount = 1000;
- int const linesize = 110;
- int const namesize = 31;
- struct standing
- {
- standing(char *t = 0) : team(t), win(), tie(), lose(), goal(), against() {}
- char *team;
- int win;
- int tie;
- int lose;
- int goal;
- int against;
- };
- struct standingcomp
- {
- bool operator()(standing const& st1, standing const& st2)
- {
- int r1 = st1.win * 3 + st1.tie;
- int r2 = st2.win * 3 + st2.tie;
- if (r1 > r2) return true;
- if (r1 < r2) return false;
- r1 = st1.win;
- r2 = st2.win;
- if (r1 > r2) return true;
- if (r1 < r2) return false;
- r1 = st1.goal - st1.against;
- r2 = st2.goal - st2.against;
- if (r1 > r2) return true;
- if (r1 < r2) return false;
- r1 = st1.goal;
- r2 = st2.goal;
- if (r1 > r2) return true;
- if (r1 < r2) return false;
- r1 = st2.win + st2.tie + st2.lose;
- r2 = st1.win + st1.tie + st1.lose;
- if (r1 > r2) return true;
- if (r1 < r2) return false;
- return strcasecmp(st1.team, st2.team) < 0;
- }
- };
- struct strcomp
- {
- bool operator()(char const *s1, char const *s2)
- { return strcmp(s1, s2) < 0; }
- };
- int main(int argc, char *argv[])
- {
- #ifndef ONLINE_JUDGE
- freopen((string(argv[0]) + ".in").c_str(), "r", stdin);
- freopen((string(argv[0]) + ".out").c_str(), "w", stdout);
- #endif
- int ncases;
- scanf("%d/n", &ncases);
- while (ncases-- > 0) {
- char tourname[linesize];
- gets(tourname);
- int nteams;
- scanf("%d/n", &nteams);
- char teams[teamcount][namesize];
- map<char *, standing, strcomp> teamstandings;
- for (int i = 0; i < nteams; ++i) {
- gets(teams[i]);
- teamstandings.insert(make_pair(teams[i], standing(teams[i])));
- }
- int ngames;
- scanf("%d/n", &ngames);
- char line[linesize];
- for (int i = 0; i < ngames; ++i) {
- gets(line);
- char team1[namesize];
- char team2[namesize];
- int goal1;
- int goal2;
- sscanf(line, "%[^#]#%d@%d#%[^#]", team1, &goal1, &goal2, team2);
- standing& st1 = teamstandings[team1];
- standing& st2 = teamstandings[team2];
- st1.goal += goal1;
- st1.against += goal2;
- st2.goal += goal2;
- st2.against += goal1;
- if (goal1 > goal2) st1.win += 1, st2.lose += 1;
- else if (goal1 < goal2) st1.lose += 1, st2.win += 1;
- else st1.tie += 1, st2.tie += 1;
- }
- vector<standing> standings;
- standings.reserve(nteams);
- for (map<char *, standing, strcomp>::iterator it = teamstandings.begin();
- it != teamstandings.end(); ++it)
- standings.push_back(it->second);
- sort(standings.begin(), standings.end(), standingcomp());
- puts(tourname);
- for (int i = 0; i < nteams; ++i)
- printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)/n",
- i + 1, standings[i].team, standings[i].win * 3 + standings[i].tie,
- standings[i].win + standings[i].tie + standings[i].lose,
- standings[i].win, standings[i].tie, standings[i].lose,
- standings[i].goal - standings[i].against, standings[i].goal,
- standings[i].against);
- if (ncases > 0) puts("");
- }
- return 0;
- }