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

#include <algorithm>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
char in[110];
vector<int> x1[110];
vector<int> y1[110];
vector<int> x2[110];
vector<int> y2[110];
vector<string> na[110];
string name[110];
int buf[11000];
int main() {
  int a;
  while (scanf("%d", &a), a) {
    int h, w;
    scanf("%d%d", &h, &w);
    for (int i = 0; i < 110; i++) {
      x1[i].clear();
      x2[i].clear();
      y1[i].clear();
      y2[i].clear();
      na[i].clear();
    }
    for (int i = 0; i < a; i++) {
      int c;
      scanf("%s%d", in, &c);
      name[i] = in;
      for (int j = 0; j < c; j++) {
        int p, q, r, s;
        scanf("%d%d%d%d%s", &p, &q, &r, &s, in);
        string tmp = in;
        x1[i].push_back(p);
        x2[i].push_back(r);
        y1[i].push_back(q);
        y2[i].push_back(s);
        na[i].push_back(tmp);
      }
    }
    int at = 0;
    for (int i = 0; i < 11000; i++)
      buf[i] = -1;
    buf[0] = 0;
    int b;
    scanf("%d", &b);
    while (b--) {
      scanf("%s", in);
      if (in[0] == 's') {
        printf("%s\\n", name[buf[at]].c_str());
      }
      if (in[0] == 'b') {
        at = max(0, at - 1);
      }
      if (in[0] == 'f') {
        if (~buf[at + 1])
          at++;
      }
      if (in[0] == 'c') {
        int to = -1;
        int x, y;
        scanf("%d%d", &x, &y);
        for (int i = 0; i < x1[buf[at]].size(); i++) {
          if (x1[buf[at]][i] <= x && x <= x2[buf[at]][i] &&
              y1[buf[at]][i] <= y && y <= y2[buf[at]][i]) {
            for (int j = 0; j < a; j++)
              if (na[buf[at]][i] == name[j])
                to = j;
            break;
          }
        }
        if (~to) {
          buf[++at] = to;
          for (int i = at + 1; i < 110; i++)
            buf[i] = -1;
        }
      }
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
char in[110];
vector<int> x1[110];
vector<int> y1[110];
vector<int> x2[110];
vector<int> y2[110];
vector<string> na[110];
string name[110];
int buf[110];
int main() {
  int a;
  while (scanf("%d", &a), a) {
    int h, w;
    scanf("%d%d", &h, &w);
    for (int i = 0; i < 110; i++) {
      x1[i].clear();
      x2[i].clear();
      y1[i].clear();
      y2[i].clear();
      na[i].clear();
    }
    for (int i = 0; i < a; i++) {
      int c;
      scanf("%s%d", in, &c);
      name[i] = in;
      for (int j = 0; j < c; j++) {
        int p, q, r, s;
        scanf("%d%d%d%d%s", &p, &q, &r, &s, in);
        string tmp = in;
        x1[i].push_back(p);
        x2[i].push_back(r);
        y1[i].push_back(q);
        y2[i].push_back(s);
        na[i].push_back(tmp);
      }
    }
    int at = 0;
    for (int i = 0; i < 110; i++)
      buf[i] = -1;
    buf[0] = 0;
    int b;
    scanf("%d", &b);
    while (b--) {
      scanf("%s", in);
      if (in[0] == 's') {
        printf("%s\\n", name[buf[at]].c_str());
      }
      if (in[0] == 'b') {
        at = max(0, at - 1);
      }
      if (in[0] == 'f') {
        if (~buf[at + 1])
          at++;
      }
      if (in[0] == 'c') {
        int to = -1;
        int x, y;
        scanf("%d%d", &x, &y);
        for (int i = 0; i < x1[buf[at]].size(); i++) {
          if (x1[buf[at]][i] <= x && x <= x2[buf[at]][i] &&
              y1[buf[at]][i] <= y && y <= y2[buf[at]][i]) {
            for (int j = 0; j < a; j++)
              if (na[buf[at]][i] == name[j])
                to = j;
            break;
          }
        }
        if (~to) {
          buf[++at] = to;
          for (int i = at + 1; i < 110; i++)
            buf[i] = -1;
        }
      }
    }
  }
}