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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>

#define X first
#define Y second
#define MP make_pair
#define MT make_tuple
#define FOR(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REP(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
using namespace std;
const int MAX = 101;
const double PI = 3.1415926535897932384;

template <class T, class U> void convert(T &t, U &u) {
  stringstream ss;
  ss << t;
  ss >> u;
}

int main() {
  string s;
  while (cin >> s) {
    if (cin.eof())
      break;

    vector<vector<char>> w(3, vector<char>(3, 0));
    FOR(i, s.size()) { w[i / 3][i % 3] = s[i]; }

    char ans = 0;
    bool d1 = true, d2 = true;
    FOR(i, 3) {
      if (i) {
        if (w[i - 1][i - 1] != w[i][i])
          d1 = false;
        if (w[2 - (i - 1)][i - 1] != w[2 - i][i])
          d2 = false;
      }

      bool t = true, y = true;
      REP(j, 1, 3) {
        if (w[i][j - 1] != w[i][j])
          y = false;
        if (w[j - 1][i] != w[j][i])
          t = false;
      }

      if (t || y) {
        if (w[i][i] != 's')
          ans = w[i][i];
      }
    }

    if (d1 || d2) {
      if (w[1][1] != 's')
        ans = w[1][1];
    }

    if (ans == 0 || ans == 's')
      cout << 'd' << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>

#define X first
#define Y second
#define MP make_pair
#define MT make_tuple
#define FOR(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REP(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
using namespace std;
const int MAX = 101;
const double PI = 3.1415926535897932384;

template <class T, class U> void convert(T &t, U &u) {
  stringstream ss;
  ss << t;
  ss >> u;
}

int main() {
  string s;
  cin >> s;
  vector<vector<vector<char>>> w(s.size() / 3,
                                 vector<vector<char>>(3, vector<char>(3, 0)));

  FOR(i, s.size()) { w[i / 3][0][i % 3] = s[i]; }

  int c = 1;
  while (cin >> s) {
    if (cin.eof())
      break;
    FOR(i, s.size()) { w[i / 3][c][i % 3] = s[i]; }
    c++;
  }

  FOR(i, w.size()) {
    char ans = 0;
    bool d1 = true, d2 = true;
    FOR(j, 3) {
      if (j) {
        if (w[i][j - 1][j - 1] != w[i][j][j])
          d1 = false;
        if (w[i][2 - (j - 1)][j - 1] != w[i][2 - j][j])
          d2 = false;
      }

      bool t = true, y = true;
      REP(k, 1, 3) {
        if (w[i][j][k - 1] != w[i][j][k])
          y = false;
        if (w[i][k - 1][j] != w[i][k][j])
          t = false;
      }

      if (t || y) {
        ans = w[i][j][0];
        break;
      }
    }

    if (d1 || d2) {
      ans = w[i][1][1];
    }

    if (ans == 0)
      cout << 'd' << endl;
    else
      cout << ans << endl;
  }

  return 0;
}