2013年8月22日

UVa 10194 - Football (aka Soccer)

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <string>
#include <vector>
#include <algorithm>
#define PB push_back
using namespace std;

struct Team {
  Team(string name) : p(0), w(0), t(0), l(0), gp(0), gd(0), gs(0), ga(0), name(name) {
    lname = name;
    for (int i = 0; lname[i]; i++) {
      lname[i] = tolower(lname[i]);
    }
  }
  bool operator<(const Team & other) const {
    if (p != other.p) {
      return p > other.p;
    }
    if (w != other.w) {
      return w > other.w;
    }
    if (gd != other.gd) {
      return gd > other.gd;
    }
    if (gs != other.gs) {
      return gs > other.gs;
    }
    if (gp != other.gp) {
      return gp < other.gp;
    }
    return lname < other.lname;
  }
  int p, w, t, l, gd, mgs, gp, gs, ga;
  string name, lname;
};

int main() {
  char s[999];
  int T;
  gets(s);
  sscanf(s, "%d", &T);
  while (T--) {
    gets(s);
    puts(s);
    int N;
    gets(s);
    sscanf(s, "%d", &N);
    vector<Team> v;
    while (N--) {
      char name[99];
      gets(name);
      v.PB(Team(name));
    }
    int M;
    gets(s);
    sscanf(s, "%d", &M);
    while (M--) {
      gets(s);
      string temp(s);
      int p1, p2, p3;
      p1 = temp.find('#');
      p2 = temp.find('@', p1);
      p3 = temp.find('#', p2);
      string team[2];
      int score[2];
      team[0] = temp.substr(0, p1);
      score[0] = atoi(temp.substr(p1 + 1, p2 - p1 - 1).c_str());
      team[1] = temp.substr(p3 + 1);
      score[1] = atoi(temp.substr(p2 + 1, p3 - p2 - 1).c_str());
      for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < 2; j++) {
          if (v[i].name == team[j]) {
            if (score[j] > score[!j]) {
              v[i].p += 3;
              v[i].w++;
            } else if (score[j] == score[!j]) {
              v[i].p += 1;
              v[i].t++;
            } else {
              v[i].p += 0;
              v[i].l++;
            }
            v[i].gp++;
            v[i].gd += score[j] - score[!j];
            v[i].gs += score[j];
            v[i].ga += score[!j];
          }
        }
      }
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
      printf("%d) %s %dp, %dg (%d-%d-%d), %dgd (%d-%d)\n", i + 1, v[i].name.c_str(), v[i].p, v[i].gp, v[i].w, v[i].t, v[i].l, v[i].gd, v[i].gs, v[i].ga);
    }
    if (T) {
      puts("");
    }
  }
  return 0;
}

沒有留言:

張貼留言