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

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI = 6 * asin(0.5);
typedef pair<double, double> P;
typedef complex<double> CP;
typedef long long ll;

int a[1000], b[1000], c[1000];

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    string s, s2;
    cin >> s;
    // cout<<s<<endl;
    // cout<<s.size()<<endl;
    if (s.size() > 80) {
      cout << "overflow" << endl;
      cin >> s2;
      continue;
    }
    rep(j, s.size()) {
      a[90 - j] = s[s.size() - j - 1] - '0';
      // cout<<s[s.size()-j-1]-'0';
    }
    // cout<<a[87]<<endl;
    cin >> s2;
    if (s2.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    rep(j, s2.size()) { b[90 - j] = s2[s2.size() - j - 1] - '0'; }
    /*
    rep(j,91) cout<<a[j];
    cout<<endl;
    rep(j,91) cout<<b[j];
    cout<<endl;
    */
    int t = 0;
    for (int j = 90; j >= 0; j--) {
      c[j] = (a[j] + b[j] + t) % 10;
      if ((a[j] + b[j] + t) > 9)
        t = 1;
      else
        t = 0;
    }
    bool f = true;
    /*
    rep(j,91) cout<<c[j];
    cout<<endl;
    */
    rep(j, 91) {
      if (f && c[j] != 0) {
        f = false;
        if (j <= 10) {
          cout << "overflow";
          break;
        }
      }
      if (!f)
        cout << c[j];
    }
    if (f)
      cout << "0";
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI = 6 * asin(0.5);
typedef pair<double, double> P;
typedef complex<double> CP;
typedef long long ll;

int a[100], b[100], c[100];
char t;
string s;

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    cin >> s;
    // cout<<s<<endl;
    rep(j, s.size()) {
      a[90 - j] = s[s.size() - j - 1] - '0';
      // cout<<s[s.size()-j-1]-'0';
    }
    // cout<<a[87]<<endl;
    cin >> s;
    rep(j, s.size()) { b[90 - j] = s[s.size() - j - 1] - '0'; }
    /*
    rep(j,91) cout<<a[j];
    cout<<endl;
    rep(j,91) cout<<b[j];
    cout<<endl;
    */
    int t = 0;
    for (int j = 90; j >= 0; j--) {
      c[j] = (a[j] + b[j] + t) % 10;
      if ((a[j] + b[j] + t) > 9)
        t = 1;
      else
        t = 0;
    }
    bool f = true;
    /*
    rep(j,91) cout<<c[j];
    cout<<endl;
    */
    rep(j, 91) {
      if (f && c[j] != 0) {
        f = false;
        if (j <= 10) {
          cout << "overflow";
          break;
        }
      }
      if (!f)
        cout << c[j];
    }
    cout << endl;
  }
  return 0;
}