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

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#define for(i, a, b) for (i = a; i < b; i++)
using namespace std;
int main(void) {
  int m, n, now, i, j, k, ff, suu, res;
  char say[21];
  int pflg[1001];
  while (cin >> m >> n && m && n) {
    for (i, 0, 1000)
      pflg[i] = 0;
    now = 0;
    res = m;
    for (i, 0, n) {
      cin >> say;
      if (res == 1)
        continue;
      if ((i + 1) % 15 == 0) {
        if (strcmp(say, "FizzBuzz") != 0)
          pflg[now] = 1, res--;
      } else if ((i + 1) % 3 == 0) {
        if (strcmp(say, "Fizz") != 0)
          pflg[now] = 1, res--;
      } else if ((i + 1) % 5 == 0) {
        if (strcmp(say, "Buzz") != 0)
          pflg[now] = 1, res--;
      } else if ((i + 1) != atoi(say))
        pflg[now] = 1, res--;
      now++;
      now = now % m;
      if (pflg[now] == 1) {
        while (1) {
          now++;
          now = now % m;
          if (pflg[now] == 0)
            break;
        }
      }
    }
    now = 0;
    while (pflg[now])
      now++;
    cout << now + 1;
    for (i, now + 1, m) {
      if (pflg[i] == 0)
        cout << " " << i + 1;
    }
    cout << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
int main(void) {
  int i, j, k, hen, cnt, fi, kk, leng, cc, rr;
  int m, n;
  char s[10002];
  int kaku;
  vector<int> pla;
  while (1) {
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;
    pla.resize(m);
    for (i = 1; i <= m; i++)
      pla[i] = 0;
    k = 1;
    cnt = 0;
    cnt = cnt + m;
    fi = n;
    for (i = 1; i <= n; i++) {
      cin >> s;

      if (cnt > 1) {
        while (1) {
          if (pla[k] == 0)
            break;
          else {
            k++;
            if (k > m)
              k = 1;
          }
        }
        if (strcmp(s, "Fizz") == 0) {
          if (i % 3 != 0) {
            pla[k] = 1;
            cnt--;
          }
        } else if (strcmp(s, "Buzz") == 0) {
          if (i % 5 != 0) {
            pla[k] = 1;
            cnt--;
          }
        } else if (strcmp(s, "FizzBuzz") == 0) {
          if (i % 3 != 0 || i % 5 != 0) {
            pla[k] = 1;
            cnt--;
          }
        } else {
          hen = 0;
          cc = 0;
          leng = strlen(s);
          rr = leng;
          if (leng <= 5) {
            if (leng == 5 && s[4] >= '0' && s[4] <= '9') {
              hen += (s[4] - '0') * 10000;
              leng--;
              cc++;
            } else if (leng == 4 && s[3] >= '0' && s[3] <= '9') {
              hen += (s[3] - '0') * 1000;
              leng--;
              cc++;
            } else if (leng == 3 && s[2] >= '0' && s[2] <= '9') {
              hen += (s[2] - '0') * 100;
              leng--;
              cc++;
            } else if (leng == 2 && s[1] >= '0' && s[1] <= '9') {
              hen += (s[1] - '0') * 10;
              leng--;
              cc++;
            } else if (leng == 1 && s[0] >= '0' && s[0] <= '9') {
              hen += (s[0] - '0');
              leng--;
              cc++;
            }
          }
          if (cc == rr) {
            if (hen % 3 == 0) {
              pla[k] = 1;
              cnt--;
            } else if (hen % 5 == 0) {
              pla[k] = 1;
              cnt--;
            }
          } else {
            pla[k] = 1;
            cnt--;
          }
        }
        k++;
        if (k > m)
          k = 1;
      } else {
      }
    }
    kaku = 0;
    for (i = 1; i <= m; i++) {
      if (kaku == 0 && pla[i] == 0) {
        cout << i;
        kaku = 1;
      } else if (pla[i] == 0)
        cout << " " << i;
    }
    cout << endl;
  }
  exit(0);
}