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

#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int dicea[6], diceb[6];
string str[21];
int mk_num(string *);

void lr_hanten(string a[]) {
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 7 / 2; j++)
      swap(a[i][j], a[i][6 - j]);
}

void ud_hanten(string a[]) {
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 7 / 2; j++)
      swap(a[j][i], a[6 - j][i]);
}

void rol_90(string a[]) {
  string b[7];
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 7; j++) {
      b[i] += a[j][6 - i];
      if (b[i][j] == '-')
        b[i][j] = '|';
      else if (b[i][j] == '|')
        b[i][j] = '-';
    }
  for (int i = 0; i < 7; i++)
    a[i] = b[i];
}

void choice(string num[], int x, int y) {
  for (int i = 0; i < 7; i++) {
    num[i] = "";
    for (int j = 0; j < 7; j++)
      num[i] += str[y + i][x + j];
  }
}

void mk_dice() {
  string num[2][7];
  // ue
  choice(num[0], 7, 0), choice(num[1], 36, 0);
  lr_hanten(num[0]), lr_hanten(num[1]);
  dicea[0] = mk_num(num[0]), diceb[0] = mk_num(num[1]);

  // hidari
  choice(num[0], 0, 7), choice(num[1], 29, 7);
  lr_hanten(num[0]), lr_hanten(num[1]);
  rol_90(num[0]), rol_90(num[1]);
  dicea[1] = mk_num(num[0]), diceb[1] = mk_num(num[1]);

  // mid_hidari
  choice(num[0], 7, 7), choice(num[1], 36, 7);
  lr_hanten(num[0]), lr_hanten(num[1]);
  dicea[2] = mk_num(num[0]), diceb[2] = mk_num(num[1]);

  // mid_migi
  choice(num[0], 14, 7), choice(num[1], 43, 7);
  lr_hanten(num[0]), lr_hanten(num[1]);
  for (int i = 0; i < 3; i++)
    rol_90(num[0]), rol_90(num[1]);
  dicea[3] = mk_num(num[0]), diceb[3] = mk_num(num[1]);

  // migi
  choice(num[0], 21, 7), choice(num[1], 50, 7);
  lr_hanten(num[0]), lr_hanten(num[1]);
  dicea[4] = mk_num(num[0]), diceb[4] = mk_num(num[1]);

  // sita
  choice(num[0], 7, 14), choice(num[1], 36, 14);
  ud_hanten(num[0]), ud_hanten(num[1]);
  lr_hanten(num[0]), lr_hanten(num[1]);
  dicea[5] = mk_num(num[0]), diceb[5] = mk_num(num[1]);
}

int main() {
  while (1) {
    for (int i = 0; i < 21; i++) {
      cin >> str[i];
      if (str[i] == "0")
        break;
    }
    if (str[0] == "0")
      break;
    mk_dice();
    int a = 0, b = 0;
    for (int i = 0; i < 6; i++)
      assert(dicea[i] != -1 && diceb[i] != -1);

    for (int i = 0; i < 6; i++)
      for (int j = 0; j < 6; j++)
        if (dicea[i] > diceb[j])
          a++;
        else if (dicea[i] < diceb[j])
          b++;

    if (a >= b)
      cout << "HIGH" << endl;
    else
      cout << "LOW" << endl;
  }
}

int mk_num(string a[]) {
  if (a[1] == "#.....#" && a[2] == "#...|.#")
    return 1;

  if (a[1] == "#..-..#" && a[2] == "#...|.#" && a[3] == "#..-..#" &&
      a[4] == "#.|...#" && a[5] == "#..-..#")
    return 2;

  if (a[1] == "#..-..#" && a[2] == "#...|.#" && a[3] == "#..-..#" &&
      a[4] == "#...|.#" && a[5] == "#..-..#")
    return 3;

  if (a[1] == "#.....#" && a[5] == "#.....#")
    return 4;

  if (a[1] == "#..-..#" && a[2] == "#.|...#" && a[3] == "#..-..#" &&
      a[4] == "#...|.#" && a[5] == "#..-..#")
    return 5;

  if (a[1] == "#..-..#" && a[2] == "#.|...#" && a[3] == "#..-..#" &&
      a[4] == "#.|.|.#" && a[5] == "#..-..#")
    return 6;

  if (a[3] == "#.....#" && a[5] == "#.....#")
    return 7;

  if (a[1] == "#..-..#" && a[2] == "#.|.|.#" && a[3] == "#..-..#" &&
      a[4] == "#.|.|.#" && a[5] == "#..-..#")
    return 8;

  if (a[1] == "#..-..#" && a[2] == "#.|.|.#" && a[3] == "#..-..#" &&
      a[4] == "#...|.#" && a[5] == "#..-..#")
    return 9;
  return -1;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int dicea[6], diceb[6];
string str[21];
int mk_num(string *);

void lr_hanten(string a[]) {
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 7 / 2; j++)
      swap(a[i][j], a[i][6 - j]);
}

void ud_hanten(string a[]) {
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 7 / 2; j++)
      swap(a[j][i], a[6 - j][i]);
}

void rol_90(string a[]) {
  string b[7];
  for (int i = 0; i < 7; i++)
    for (int j = 0; j < 7; j++) {
      b[i] += a[j][6 - i];
      if (b[i][j] == '-')
        b[i][j] = '|';
      else if (b[i][j] == '|')
        b[i][j] = '-';
    }
  for (int i = 0; i < 7; i++)
    a[i] = b[i];
}

void choice(string num[], int x, int y) {
  for (int i = 0; i < 7; i++) {
    num[i] = "";
    for (int j = 0; j < 7; j++)
      num[i] += str[y + i][x + j];
  }
}

void mk_dice() {
  string num[2][7];
  // ue
  choice(num[0], 7, 0), choice(num[1], 36, 0);
  lr_hanten(num[0]), lr_hanten(num[1]);
  dicea[0] = mk_num(num[0]), diceb[0] = mk_num(num[1]);

  // hidari
  choice(num[0], 0, 7), choice(num[1], 29, 7);
  lr_hanten(num[0]), lr_hanten(num[1]);
  rol_90(num[0]), rol_90(num[1]);
  dicea[1] = mk_num(num[0]), diceb[1] = mk_num(num[1]);

  // mid_hidari
  choice(num[0], 7, 7), choice(num[1], 36, 7);
  lr_hanten(num[0]), lr_hanten(num[1]);
  dicea[2] = mk_num(num[0]), diceb[2] = mk_num(num[1]);

  // mid_migi
  choice(num[0], 14, 7), choice(num[1], 43, 7);
  lr_hanten(num[0]), lr_hanten(num[1]);
  for (int i = 0; i < 3; i++)
    rol_90(num[0]), rol_90(num[1]);
  dicea[3] = mk_num(num[0]), diceb[3] = mk_num(num[1]);

  // migi
  choice(num[0], 21, 7), choice(num[1], 50, 7);
  lr_hanten(num[0]), lr_hanten(num[1]);
  dicea[4] = mk_num(num[0]), diceb[4] = mk_num(num[1]);

  // sita
  choice(num[0], 7, 14), choice(num[1], 36, 14);
  ud_hanten(num[0]), ud_hanten(num[1]);
  lr_hanten(num[0]), lr_hanten(num[1]);
  dicea[5] = mk_num(num[0]), diceb[5] = mk_num(num[1]);
}

int main() {
  while (1) {
    for (int i = 0; i < 21; i++) {
      cin >> str[i];
      if (str[i] == "0")
        break;
    }
    if (str[0] == "0")
      break;
    mk_dice();
    sort(dicea, dicea + 6);
    sort(diceb, diceb + 6);
    int a = 0, b = 0;
    for (int i = 0; i < 6; i++)
      assert(dicea[i] != -1 && diceb[i] != -1);

    for (int i = 0; i < 1000; i++) {
      if (dicea[rand() % 6] > diceb[rand() % 6])
        a++;
      else if (dicea[rand() % 6] < diceb[rand() % 6])
        b++;
    }
    if (a >= b)
      cout << "HIGH" << endl;
    else
      cout << "LOW" << endl;
  }
}

int mk_num(string a[]) {
  if (a[1] == "#.....#" && a[2] == "#...|.#")
    return 1;

  if (a[1] == "#..-..#" && a[2] == "#...|.#" && a[3] == "#..-..#" &&
      a[4] == "#.|...#" && a[5] == "#..-..#")
    return 2;

  if (a[1] == "#..-..#" && a[2] == "#...|.#" && a[3] == "#..-..#" &&
      a[4] == "#...|.#" && a[5] == "#..-..#")
    return 3;

  if (a[1] == "#......#" && a[5] == "#......#")
    return 4;

  if (a[1] == "#..-..#" && a[2] == "#.|...#" && a[3] == "#..-..#" &&
      a[4] == "#...|.#" && a[5] == "#..-..#")
    return 5;

  if (a[1] == "#..-..#" && a[2] == "#.|...#" && a[3] == "#..-..#" &&
      a[4] == "#.|.|.#" && a[5] == "#..-..#")
    return 6;

  if (a[3] == "#......#" && a[5] == "#......#")
    return 7;

  if (a[1] == "#..-..#" && a[2] == "#.|.|.#" && a[3] == "#..-..#" &&
      a[4] == "#.|.|.#" && a[5] == "#..-..#")
    return 8;

  if (a[1] == "#..-..#" && a[2] == "#.|.|.#" && a[3] == "#..-..#" &&
      a[4] == "#...|.#" && a[5] == "#..-..#")
    return 9;
  return -1;
}