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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define fr(i, c)                                                               \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr << #x << " = " << (x) << endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;

char alpha[38][3];
char in[99];
int n, d[38][38];

int main() {
  char ex[][3] = {"ld", "mb", "mp", "nc", "nd", "ng",
                  "nt", "nw", "ps", "qu", "cw", "ts"};
  rep(i, 26) alpha[i][0] = 'a' + i;
  rep(i, 12) strcpy(alpha[i + 26], ex[i]);

  scanf("%d ", &n);
  rep(i, n) {
    fgets(in, 100, stdin);
    int prev = -1, cur;
    for (int j = 0; in[j]; j++) {
      if (in[j] == ' ') {
        prev = -1;
        continue;
      }
      for (cur = 37; cur >= 26; cur--) {
        if (alpha[cur][0] == in[j] && alpha[cur][1] == in[j + 1])
          break;
      }
      if (cur == 25)
        cur = in[j] - 'a';
      if (prev >= 0 && cur >= 0)
        d[prev][cur]++;
      prev = cur;
      if (26 <= cur && cur < 38)
        j++;
    }
  }
  rep(i, 38) {
    int mx = max_element(d[i], d[i] + 38) - d[i];
    printf("%s %s %d\\n", alpha[i], alpha[mx], d[i][mx]);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define fr(i, c)                                                               \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr << #x << " = " << (x) << endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;

char alpha[38][3];
char in[99];
int n, d[38][38];

int main() {
  char ex[][3] = {"ld", "mb", "mp", "nc", "nd", "ng",
                  "nt", "nw", "ps", "qu", "cw", "ts"};
  rep(i, 26) alpha[i][0] = 'a' + i;
  rep(i, 12) strcpy(alpha[i + 26], ex[i]);

  scanf("%d ", &n);
  rep(i, n) {
    fgets(in, 100, stdin);
    int prev = -1, cur;
    for (int j = 0; in[j]; j++) {
      if (in[j] == ' ') {
        prev = -1;
        continue;
      }
      for (cur = 37; cur >= 26; cur--) {
        if (alpha[cur][0] == in[j] && alpha[cur][1] == in[j + 1])
          break;
      }
      if (cur == 25)
        cur = in[j] - 'a';
      if (prev >= 0)
        d[prev][cur]++;
      prev = cur;
      if (cur >= 26)
        j++;
    }
  }
  rep(i, 38) {
    int mx = max_element(d[i], d[i] + 38) - d[i];
    printf("%s %s %d\\n", alpha[i], alpha[mx], d[i][mx]);
  }
  return 0;
}