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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

#define pb push_back
#define fs first
#define sc second
#define openfile                                                               \\
  {                                                                            \\
    freopen("input.txt", "r", stdin);                                          \\
    freopen("output.txt", "w", stdout);                                        \\
  }
#define debug 0

struct card {
  char x, y;

  bool operator>(const card &a) {
    if (y != a.y) {
      if (a.y == 'S' && (y == 'H' || y == 'D' || y == 'C'))
        return true;
      if (a.y == 'H' && (y == 'D' || y == 'C'))
        return true;
      if (a.y == 'D' && y == 'C')
        return true;
      return false;
    }
    if (a.x <= '9' && x > a.x)
      return true;
    if (a.x == 'T' && (x == 'J' || x == 'Q' || x == 'K' || x == 'A'))
      return true;
    if (a.x == 'J' && (x == 'Q' || x == 'K' || x == 'A'))
      return true;
    if (a.x == 'Q' && (x == 'K' || x == 'A'))
      return true;
    if (a.x == 'K' && x == 'A')
      return true;
    return false;
  }
};

card a[5][20];
char trumph;

void inputFile() {
  for (int k = 1; k <= 4; k++)
    for (int i = 1; i <= 13; i++) {
      char x;
      scanf("%c%c%c", &a[k][i].x, &a[k][i].y, &x);
    }
}

void solve() {
  int turn = 1;
  int EW = 0, NS = 0;
  for (int i = 1; i <= 13; i++) {
    card maxx = a[1][i];
    int x = 1;
    for (int j = 2; j <= 4; j++)
      if (a[j][i].y == trumph) {
        if (maxx.y != trumph || a[j][i] > maxx) {
          maxx = a[j][i];
          x = j;
        }
      }
    if (maxx.y == trumph) {
      if (x == 1 || x == 3)
        NS++;
      else
        EW++;
      turn = x;
      continue;
    }

    maxx = a[turn][i];
    x = turn;
    for (int j = 1; j <= 4; j++)
      if (j != turn && a[j][i].y == a[turn][i].y && a[j][i] > maxx) {
        maxx = a[j][i];
        x = j;
      }
    if (x == 1 || x == 3)
      NS++;
    else
      EW++;
    turn = x;
  }
  if (EW > NS)
    printf("EW %d\\n", EW - 6);
  else
    printf("NS %d\\n", NS - 6);
}

int main() {
  if (debug)
    openfile;

  while (scanf("%c\\n", &trumph) && trumph != '#') {
    inputFile();
    solve();
  }

  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
  int i, j, k, l, m, n, T, w;
  char C[4][13][3];
  char p[3];
  char cc, tt, trumph;
  FILE *fin;
  fin = fopen("A.txt", "r");
  while (true) {
    fscanf(fin, "%s", p);
    trumph = p[0];
    w = 0;
    if (trumph == '#') {
      break;
    }
    for (i = 0; i < 4; i++) {
      for (j = 0; j < 13; j++) {
        fscanf(fin, "%s", C[i][j]);
        switch (C[i][j][0]) {
        case 'T':
          C[i][j][0] = '0' + 10;
          break;
        case 'J':
          C[i][j][0] = '0' + 11;
          break;
        case 'Q':
          C[i][j][0] = '0' + 12;
          break;
        case 'K':
          C[i][j][0] = '0' + 13;
          break;
        case 'A':
          C[i][j][0] = '0' + 14;
          break;
        default:
          break;
        }
      }
    }
    m = 0;
    n = 0;
    w = 0;
    for (i = 0; i < 13; i++) {
      cc = 0;
      tt = trumph;
      for (j = 0; j < 4; j++) {
        if (C[j][i][1] == trumph) {
          cc = 1;
        }
      }
      if (!cc) {
        tt = C[w][i][1];
      }
      k = 0;
      l = '0';
      for (j = 0; j < 4; j++) {
        if (C[j][i][1] == tt && C[j][i][0] > l) {
          l = C[j][i][0];
          k = j % 2;
          w = j;
        }
      }
      if (!k) {
        m++;
      } else {
        n++;
      }
    }
    if (m > n) {
      printf("NS %d\\n", m - 6);
    } else {
      printf("EW %d\\n", n - 6);
    }
  }
  return 0;
}