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

#include <algorithm>
#include <iostream>
#include <sstream>

using namespace std;

int main() {
  string HRSP[22] = {"Rock",  "Fire",   "Scissors", "Snake",     "Human",
                     "Tree",  "Wolf",   "Sponge",   "Paper",     "Air",
                     "Water", "Dragon", "Devil",    "Lightning", "Gun",
                     "Rock",  "Fire",   "Scissors", "Snake",     "Human",
                     "Tree",  "Wolf"};
  int number; // numberÍ1000¢
  string hand;
  while (cin >> number) {
    bool hands[22];
    for (int b = 0; b < 22; b++) {
      hands[b] = 1;
    }
    if (!number)
      break; // 0ªfalse¾ÆvÁÄ¢é
    //		if(!number) break;

    for (int j = 0; j < number; j++) {
      cin >> hand;
      for (int i = 0; i < 15; i++) {
        if (hand == HRSP[i]) {
          hands[i] = 0;
          break;
        }
      }
    }
    // for(int i=0;i<15;i++){
    //	cout << i << ":" << hands[i] << endl;
    // }

    int sum = 0;
    for (int i = 0; i < 15; i++) {
      sum += !hands[i];
    }

    // handîñÌRs[
    for (int i = 0; i < 7; i++) {
      hands[i + 15] = hands[i];
      //			cout << hands[i] << endl;
    }

    bool flag = 1;
    int count = 0;
    string win_hand = "Draw";

    //		cout << sum << endl;
    if (sum == 1) { //  ¢±ÌêÅèªêÊè
      //			cout <<"hitotoori" << endl;
      cout << win_hand << endl;
      continue;
    }

    for (int index = 0; index < 22; index++) {
      flag &= hands[index];
      if (count >= 7 && !flag) {
        win_hand = HRSP[index];
        break;
      } else if (!flag) {
        flag = !flag;
        count = 0;
      } else {
        count++;
      }
    }
    cout << win_hand << endl;
  }
}

// Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water,
// Dragon, Devil, Lightning, and Gun.

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <sstream>

using namespace std;

int main() {
  string HRSP[15] = {"Rock",  "Fire",   "Scissors", "Snake",     "Human",
                     "Tree",  "Wolf",   "Sponge",   "Paper",     "Air",
                     "Water", "Dragon", "Devil",    "Lightning", "Gun"};
  int number; // numberÍ1000¢
  string hand;
  while (cin >> number) {
    bool hands[22];
    for (int b = 0; b < 22; b++) {
      hands[b] = 1;
    }
    if (!number)
      break; // 0ªtrue¾ÆvÁÄ¢é

    for (int j = 0; j < number; j++) {
      cin >> hand;
      for (int i = 0; i < 15; i++) {
        if (hand == HRSP[i]) {
          hands[i] = 0;
          break;
        }
      }
    }
    for (int i = 0; i < 7; i++) {
      hands[i + 15] = hands[i];
      //			cout << hands[i] << endl;
    }
    bool hantei = 1;
    int index = 0;
    int count = 0;
    string win_hand = "Draw";
    for (; index < 15;) {
      hantei &= hands[index];
      // cout << "hantei:" << hantei << endl;
      if (!hantei) {
        hantei = !hantei;
        index++;
        count = 0;
        continue;
      } else {
        index++;
        count++;
        if (count == 7) {
          win_hand = HRSP[index];
          // cout << HRSP[index] << endl;
          break;
        }
        continue;
      }
    }

    //		for(int i=0;i<22;i++){
    ////			hands[i+15] = hands[i];
    //			cout << i << ":" <<hands[i] << endl;
    //		}
    //		cout <<"kiteru?" << endl;
    cout << win_hand << endl;
  }
}

// Rock, Fire, Scissors, Snake, Human, Tree, Wolf, Sponge, Paper, Air, Water,
// Dragon, Devil, Lightning, and Gun.