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

#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

struct Score {
  int student_number;
  int score;
  Score() { score = 0; }
  bool operator>(const Score &o) const {
    return score == o.score ? student_number < o.student_number
                            : score > o.score;
  }
};

int calc_score(istringstream &is) {
  vector<pair<int, int>> frame(12); // フレームごとの投球情報. 1-indexed

  int score = 0;

  int bonus_spare = 0;
  int bonus_strike = 0;
  int pin;
  int cur_frame = 1;
  int cur_pin = 0;
  bool first_bowl = true;
  while (is >> pin) {
    if (cur_frame != 11)
      score += pin;
    if (bonus_spare) {
      score += pin * bonus_spare;
      bonus_spare = bonus_strike;
      bonus_strike = 0;
    }
    //        cout << score << ' ';

    if (cur_frame == 11) {
      if (first_bowl) {
        frame[cur_frame].first = pin;
        first_bowl = false;
      } else {
        frame[cur_frame].second = pin;
      }
      continue;
    }

    if (pin == 10) {
      if (first_bowl) {
        frame[cur_frame].first = 10;
        frame[cur_frame].second = -1; // 投球がなかったことのフラグ
        cur_frame++;
        bonus_spare++;
        bonus_strike++;
        first_bowl = true;
      } else {
        frame[cur_frame].second = 10;
        cur_frame++;
        bonus_spare++;
        first_bowl = true;
      }
      continue;
    }

    if (first_bowl) {
      frame[cur_frame].first = pin;
      first_bowl = false;
    } else {
      frame[cur_frame].second = pin;
      if (frame[cur_frame].first + frame[cur_frame].second >= 10)
        bonus_spare++;
      first_bowl = true;
      cur_frame++;
    }
  }
  return score;
}

int main() {
  int n;
  while (cin >> n, n != 0) {
    cin.ignore(1);
    vector<Score> info(n);
    for (int i = 0; i < n; i++) {
      Score score;
      string s;
      getline(cin, s);
      istringstream is(s);
      is >> score.student_number;
      score.score = calc_score(is);
      info[i] = score;
    }
    sort(info.begin(), info.end(), greater<Score>());
    for (int i = 0; i < info.size(); i++) {
      cout << info[i].student_number << ' ' << info[i].score << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;

struct Score {
  int student_number;
  int score;
  Score() { score = 0; }
  bool operator>(const Score &o) const {
    return score == o.score ? student_number < o.student_number
                            : score > o.score;
  }
};

int calc_score(istringstream &is) {
  vector<pair<int, int>> frame(12); // フレームごとの投球情報. 1-indexed

  int score = 0;

  int bonus_spare = 0;
  int bonus_strike = 0;
  int pin;
  int cur_frame = 1;
  int cur_pin = 0;
  bool first_bowl = true;
  while (is >> pin) {
    if (cur_frame != 11)
      score += pin;
    if (bonus_spare) {
      score += pin * bonus_spare;
      bonus_spare = bonus_strike;
      bonus_strike = 0;
    }
    //        cout << score << ' ';

    if (cur_frame == 11) {
      if (first_bowl) {
        frame[cur_frame].first = pin;
        first_bowl = false;
      } else {
        frame[cur_frame].second = pin;
      }
      continue;
    }

    if (pin == 10) {
      assert(first_bowl == true);
      frame[cur_frame].first = 10;
      frame[cur_frame].second = -1; // 投球がなかったことのフラグ
      cur_frame++;
      bonus_spare++;
      bonus_strike++;
      continue;
    }

    if (first_bowl) {
      frame[cur_frame].first = pin;
      first_bowl = false;
    } else {
      frame[cur_frame].second = pin;
      if (frame[cur_frame].first + frame[cur_frame].second == 10)
        bonus_spare++;
      first_bowl = true;
      cur_frame++;
    }
  }
  return score;
}

int main() {
  int n;
  while (cin >> n, n != 0) {
    cin.ignore(1);
    vector<Score> info(n);
    for (int i = 0; i < n; i++) {
      Score score;
      string s;
      getline(cin, s);
      istringstream is(s);
      is >> score.student_number;
      score.score = calc_score(is);
      info[i] = score;
    }
    sort(info.begin(), info.end(), greater<Score>());
    for (int i = 0; i < info.size(); i++) {
      cout << info[i].student_number << ' ' << info[i].score << endl;
    }
  }
  return 0;
}