Problem p00768 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>

using namespace std;

struct team {
  team() {
    for (int i = 0; i < 10; ++i) {
      ac[i] = -1;
      fa[i] = 0;
    }
  }
  int no;
  int ac[10];
  int fa[10];

  int na() const {
    int ans = 0;
    for (int i = 0; i < 10; ++i)
      if (ac[i] != -1)
        ++ans;
    return ans;
  }

  int st() const {
    int ans = 0;
    for (int i = 0; i < 10; ++i)
      if (ac[i] != -1)
        ans += ac[i] + fa[i] * 20;
    return ans;
  }

  bool operator==(const team &rh) const {
    return this->na() == rh.na() && this->st() == rh.st();
  }

  bool operator<(const team &rh) const {
    if (this->na() > rh.na())
      return true;
    else if (this->na() < rh.na())
      return false;

    if (this->st() < rh.st())
      return true;
    else if (this->st() > rh.st())
      return false;

    return this->no > rh.no;
  }
};

int main() {
  for (;;) {
    int m, t, p, r;
    scanf("%d %d %d %d", &m, &t, &p, &r);
    if (m == 0 && t == 0 && p == 0 && r == 0)
      break;

    team teams[50];
    for (int i = 0; i < t; ++i)
      teams[i].no = i + 1;

    for (int i = 0; i < r; ++i) {
      int m, t, p, j;
      scanf("%d %d %d %d", &m, &t, &p, &j);

      if (j == 0)
        teams[t - 1].ac[p - 1] = m;
      else
        teams[t - 1].fa[p - 1] += 1;
    }

    sort(teams, teams + t);

    for (int i = 0; i < t; ++i) {
      printf("%d", teams[i].no);
      if (i == t - 1)
        printf("\\n");
      else if (teams[i] == teams[i + 1])
        printf("=");
      else
        printf(",");
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>

using namespace std;

struct team {
  team() {
    for (int i = 0; i < 10; ++i) {
      ac[i] = -1;
      fa[i] = 0;
    }
  }
  int no;
  int ac[10];
  int fa[10];

  int na() const {
    int ans = 0;
    for (int i = 0; i < 10; ++i)
      if (ac[i] != -1)
        ++ans;
    return ans;
  }

  int st() const {
    int ans = 0;
    for (int i = 0; i < 10; ++i)
      if (ac[i] != -1)
        ans += ac[i] + fa[i] * 20;
    return ans;
  }

  bool operator==(const team &rh) {
    return this->na() == rh.na() && this->st() == rh.st();
  }

  bool operator<(const team &rh) const {
    if (this->na() > rh.na())
      return true;
    else if (this->na() < rh.na())
      return false;

    if (this->st() < rh.st())
      return true;
    else if (this->st() > rh.st())
      return false;

    return this->no > rh.no;
  }
};

int main() {
  for (;;) {
    int m, t, p, r;
    scanf("%d %d %d %d", &m, &t, &p, &r);
    if (m == 0 && t == 0 && p == 0 && r == 0)
      break;

    team teams[10];
    for (int i = 0; i < t; ++i)
      teams[i].no = i + 1;

    for (int i = 0; i < r; ++i) {
      int m, t, p, j;
      scanf("%d %d %d %d", &m, &t, &p, &j);

      if (j == 0)
        teams[t - 1].ac[p - 1] = m;
      else if (j == 1)
        teams[t - 1].fa[p - 1] += 1;
    }

    sort(teams, teams + t);

    for (int i = 0; i < t; ++i) {
      printf("%d", teams[i].no);
      if (i == t - 1)
        printf("\\n");
      else if (teams[i] == teams[i + 1])
        printf("=");
      else
        printf(",");
    }
  }

  return 0;
}