alexjercan/bugnet huggingface dataset:
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <utility>
using namespace std;
int main() {
  int m;
  string in1, in2;
  int a[1000], b[1000], ans[1000];
  int f;
  int alen, blen, mlen;
  cin >> m;
  while (m--) {
    for (int i = 0; i < 90; i++) {
      a[i] = b[i] = ans[i] = 0;
    }
    in1 = "";
    in2 = "";
    cin >> in1;
    cin >> in2;
    alen = in1.size();
    blen = in2.size();
    for (int i = 0; i < alen; i++) {
      a[alen - 1 - i] = in1[i] - '0';
    }
    for (int i = 0; i < blen; i++) {
      b[blen - 1 - i] = in2[i] - '0';
    }
    mlen = max(alen, blen);
    if (mlen > 80) {
      cout << "overflow" << endl;
      continue;
    }
    f = 0;
    for (int i = 0; i < mlen + 1; i++) {
      ans[i] = (a[i] + b[i] + f) % 10;
      f = (a[i] + b[i] + f) / 10;
    }
    if (ans[mlen] != 0) {
      if (mlen > 79) {
        cout << "overflow" << endl;
        continue;
      }
      cout << ans[mlen];
    }

    for (int i = 0; i < mlen; i++) {
      cout << ans[mlen - 1 - i];
    }
    cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <utility>
using namespace std;
int main() {
  int m;
  string in, in2;
  int a[90], b[90], ans[90];
  int f;
  int alen, blen, mlen;
  cin >> m;
  while (m--) {
    for (int i = 0; i < 90; i++) {
      a[i] = b[i] = ans[i] = 0;
    }
    cin >> in;
    cin >> in2;
    alen = in.size();
    blen = in2.size();
    for (int i = 0; i < alen; i++) {
      a[alen - 1 - i] = in[i] - '0';
    }
    for (int i = 0; i < blen; i++) {
      b[blen - 1 - i] = in[i] - '0';
    }
    mlen = max(alen, blen);
    if (mlen > 80) {
      cout << "overflow" << endl;
      continue;
    }
    f = 0;
    for (int i = 0; i < mlen + 1; i++) {
      ans[i] = (a[i] + b[i] + f) % 10;
      f = (a[i] + b[i] + f) / 10;
    }
    if (ans[mlen] != 0) {
      // if(mlen>79){
      // cout<<"overflow"<<endl;
      continue;
      //}
      // cout<<ans[mlen];
    }

    for (int i = 0; i < mlen; i++) {
      // cout<<ans[mlen-1-i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    char str1[1000];
    char str2[1000];
    string ans = "";
    cin >> str1;
    cin >> str2;
    int m1 = strlen(str1) - 1, m2 = strlen(str2) - 1, pre = 0;
    int m = max(m1, m2);
    for (int j = 0; j <= m; j++) {
      int sum = pre;
      sum += (m1 >= 0) ? str1[m1--] - '0' : 0;
      sum += (m2 >= 0) ? str2[m2--] - '0' : 0;
      pre = sum / 10;
      sum -= pre * 10;
      ans += '0' + sum;
    }
    if (pre > 0)
      ans += '0' + pre;
    reverse(ans.begin(), ans.end());
    if (ans.length() > 80)
      cout << "overflow" << endl;
    else
      cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    char str1[82];
    char str2[82];
    string ans = "";
    cin >> str1;
    cin >> str2;
    int m1 = strlen(str1) - 1, m2 = strlen(str2) - 1, pre = 0;
    int m = max(m1, m2);
    for (int j = 0; j <= m; j++) {
      int sum = pre;
      sum += (m1 >= 0) ? str1[m1--] - '0' : 0;
      sum += (m2 >= 0) ? str2[m2--] - '0' : 0;
      pre = sum / 10;
      sum -= pre * 10;
      ans += '0' + sum;
    }
    if (pre > 0)
      ans += '0' + pre;
    reverse(ans.begin(), ans.end());
    if (ans.length() > 80)
      cout << "overflow" << endl;
    else
      cout << ans << endl;
  }
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()

int main() {
  string in1, in2;
  int t;
  scanf("%d", &t);
  while (t--) {
    char str[100];
    cin >> in1 >> in2;
    if (in1.size() > 80 || in2.size() > 80) {
      puts("overflow");
      continue;
    }
    reverse(all(in1));
    reverse(all(in2));
    int k = 0;
    int i;
    for (i = 0; i < min(in1.size(), in2.size()); i++) {
      k = (in1[i] - '0') + (in2[i] - '0') + k;
      str[i] = (k % 10) + '0';
      k /= 10;
    }
    if (i == in1.size()) { // in2
      for (; i < in2.size(); i++) {
        k = (in2[i] - '0') + k;
        str[i] = (k % 10) + '0';
        k /= 10;
      }
    } else { // in1
      for (; i < in1.size(); i++) {
        k = (in1[i] - '0') + k;
        str[i] = (k % 10) + '0';
        k /= 10;
      }
    }
    if (k != 0)
      str[i++] = k + '0';
    str[i] = 0;
    if (i > 80) {
      puts("overflow");
      continue;
    }
    reverse(str, str + i);
    puts(str);
  }

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()

int main() {
  string in1, in2;
  int t;
  scanf("%d", &t);
  while (t--) {
    char str[100];
    cin >> in1 >> in2;
    reverse(all(in1));
    reverse(all(in2));
    int k = 0;
    int i;
    for (i = 0; i < min(in1.size(), in2.size()); i++) {
      k = (in1[i] - '0') + (in2[i] - '0') + k;
      str[i] = (k % 10) + '0';
      k /= 10;
    }
    if (i == in1.size()) { // in2
      for (; i < in2.size(); i++) {
        k = (in2[i] - '0') + k;
        str[i] = (k % 10) + '0';
        k /= 10;
      }
    } else { // in1
      for (; i < in1.size(); i++) {
        k = (in1[i] - '0') + k;
        str[i] = (k % 10) + '0';
        k /= 10;
      }
    }
    if (k != 0)
      str[i++] = k + '0';
    str[i] = 0;
    reverse(str, str + i);
    puts(str);
  }

  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>

using namespace std;

class compute {
private:
  vector<int> sum;
  int carry, temp;
  void Init();

public:
  void calc(string s1, string s2);
};

void compute::Init() { sum.clear(); }

void compute::calc(string s1, string s2) {
  Init();
  int a = s1.size();
  int b = s2.size();

  if (a > 80 || b > 80) {
    cout << "overflow" << endl;
    return;
  }

  a--;
  b--;
  carry = 0;

  while (a >= 0 || b >= 0) {
    temp = 0;
    if (a >= 0) {
      temp += (s1[a] - '0');
    }
    if (b >= 0) {
      temp += (s2[b] - '0');
    }
    sum.push_back((temp + carry) % 10);
    carry = (temp + carry) / 10;
    a--;
    b--;
  }
  if (carry) {
    sum.push_back(carry);
  }
  if (sum.size() > 80) {
    cout << "overflow" << endl;
    return;
  }
  for (int i = sum.size() - 1; i >= 0; i--) {
    cout << sum[i];
  }
  cout << endl;
}

int main(void) {

  int n;
  string s1, s2;
  compute s;

  cin >> n;

  while (n-- > 0) {
    cin >> s1 >> s2;
    s.calc(s1, s2);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
  int n = 0;
  char i1[100], i2[100], o[100];
  int li1 = 0, li2 = 0;
  int d1[81], d2[81], d[81];
  int c = 0;

  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    c = 0;
    scanf("%s", i1);
    scanf("%s", i2);
    li1 = strlen(i1);
    li2 = strlen(i2);
    if (li1 > 80 || li2 > 80) {
      puts("overflow");
      continue;
    }
    for (int j = 0; j < 81; ++j) {
      d1[j] = d2[j] = d[j] = 0;
    }
    for (int j = 0; j < li1; ++j) {
      d1[j] = *(i1 + li1 - j - 1) - '0';
    }
    for (int j = 0; j < li2; ++j) {
      d2[j] = *(i2 + li2 - j - 1) - '0';
    }
    for (int j = 0; j < 81; ++j) {
      d[j] = d1[j] + d2[j] + c;
      c = d[j] >= 10 ? 1 : 0;
      d[j] -= 10 * c;
    }
    for (c = 80; c >= 0; --c) {
      if (d[c] != 0) {
        break;
      }
    }
    if (c == 80) {
      puts("overflow");
      continue;
    }
    for (int j = 0; j <= c; ++j) {
      o[j] = d[c - j] + '0';
    }
    o[c + 1] = '\\0';
    printf("%s\\n", o);
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, b, c;
    cin >> a >> b;
    if (a.size() < b.size())
      swap(a, b);
    int as = a.size(), bs = b.size();
    for (int i = 0; i < as - bs; i++)
      b = "0" + b;
    c = a;
    bool kuri = false;
    int sum = 0;
    for (int i = a.size() - 1; i >= 0; i--) {
      sum = a[i] - '0';
      char now;
      sum = sum + b[i] - '0';
      if (kuri)
        sum++;
      if (sum >= 10) {
        kuri = true;
        sum -= 10;
        // cout<<"a";
      } else {
        kuri = false;
      }
      now = sum + '0';
      // cout<<sum;
      c[i] = now;
    }
    if (kuri)
      c = "1" + c;

    if (c.size() > 80)
      cout << "overflow" << endl;
    else
      cout << c << endl;
    c.clear();
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define pd pair<double, double>

string rever(string a) {
  string b = a;
  for (int i = 0; i < a.size(); i++)
    b[i] = a[a.size() - i - 1];
  // cout<<b<<endl;
  return b;
}

int main() {
  string a, b, c;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    c = "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
        "ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
        "ssssssssssssssssssssssssssssssssss";
    if (a.size() < b.size())
      swap(a, b);
    b = rever(b);
    cout << c << endl;
    // cout<<a<<" "<<b<<endl;
    for (int i = 0; i <= a.size() - b.size(); i++) {
      b.push_back('0');
    }
    b = rever(b);
    int as = a.size();
    bool kuriagari = false;
    for (int i = as - 1; i >= 0; i--) {
      int n1 = a[i] - '0';
      int n2 = b[i] - '0';
      int ans = 0;
      ans = n1 + n2;
      if (kuriagari)
        ans++;
      if (ans >= 10) {
        kuriagari = true;
        ans -= 10;
      } else
        kuriagari = false;
      c[i] = ans + '0';
    }

    if (c.find("s") != string::npos) {
      int fin = c.find("s");
      c.erase(fin);
    }
    // cout<<c<<endl;

    if (c.size() < 80)
      cout << c << endl;
    else
      cout << "overfllow" << endl;
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {

  int n;
  cin >> n;
  for (int iii = 0; iii < n; iii++) {
    string st1, st2;
    int n1[83] = {}, n2[83] = {};
    cin >> st1 >> st2;

    int r = st1.size();
    int N[83] = {};
    int y = 0;
    if (r < st2.size())
      r = st2.size();
    if (st1.size() > 80 || st2.size() > 80)
      r = 81;
    else {
      for (int i = 0; i < st1.size(); i++)
        n1[i] = st1[st1.size() - i - 1] - '0';
      for (int i = 0; i < st2.size(); i++)
        n2[i] = st2[st2.size() - i - 1] - '0';

      for (int i = 0; i < r; i++) {
        N[i] = (n1[i] + n2[i] + y) % 10;
        y = (n1[i] + n2[i] + y) / 10;
        if (i == r - 1 && y > 0)
          r++;
      }
    }
    if (r > 80)
      cout << "overflow" << endl;
    else {
      for (int i = 0; i < r; i++)
        cout << N[r - i - 1];
      cout << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {

  int n;
  cin >> n;
  for (int iii = 0; iii < n; iii++) {
    string st1, st2;
    int n1[83] = {}, n2[83] = {};
    cin >> st1 >> st2;
    for (int i = 0; i < st1.size(); i++)
      n1[i] = st1[st1.size() - i - 1] - '0';
    for (int i = 0; i < st2.size(); i++)
      n2[i] = st2[st2.size() - i - 1] - '0';
    int N[83] = {};
    int y = 0;

    int r = st1.size();
    if (r < st2.size())
      r = st2.size();
    for (int i = 0; i < r; i++) {
      N[i] = (n1[i] + n2[i] + y) % 10;
      y = (n1[i] + n2[i] + y) / 10;
      if (i == r - 1 && y > 0)
        r++;
    }
    if (r > 81)
      cout << "overflow" << endl;
    else {
      for (int i = 0; i < r; i++)
        cout << N[r - i - 1];
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <math.h>
#include <stdio.h>
#include <string.h>

int main(void) {

  int N, math1, math2, kuri, keta;
  int i, j, k, q, leng1, leng2;
  char fi[10000], se[10000], ans[10000];

  scanf("%d", &N);

  for (i = 0; i < N; i++) {

    for (j = 0; j < 1000; j++) {
      ans[j] = '\\0';
      fi[j] = '\\0';
      se[j] = '\\0';
    }

    scanf("%s", &fi);
    scanf("%s", &se);

    for (j = 0; fi[j] != '\\0'; j++) {
    }
    leng1 = j;
    for (j = 0; se[j] != '\\0'; j++) {
    }
    leng2 = j;
    if (leng1 <= 80 && leng2 <= 80) {
      for (j = leng1 - 1, k = leng2 - 1, keta = 0, kuri = 0; j >= 0 || k >= 0;
           j--, k--, keta++) {
        if (j < 0)
          math1 = 0;
        else
          math1 = fi[j] - '0';
        if (k < 0)
          math2 = 0;
        else
          math2 = se[k] - '0';
        ans[keta] = ((math1 + math2 + kuri) % 10) + '0';
        kuri = (math1 + math2 + kuri) / 10;
      }
      q = 0;
      if (kuri == 1)
        ans[keta] = '1', q = 1;
      if (keta + q <= 80) {
        for (j = keta - 1 + q; j >= 0; j--) {
          printf("%c", ans[j]);
        }
      } else
        printf("overflow");
    } else
      printf("overflow");
    printf("\\n");
    for (j = 0; j < 1000; j++) {
      ans[j] = '\\0';
      fi[j] = '\\0';
      se[j] = '\\0';
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>
#include <string.h>

int main(void) {

  int N, math1, math2, kuri, keta;
  int i, j, k;
  char fi[100], se[100], ans[100];

  scanf("%d", &N);

  for (i = 0; i < N; i++) {

    scanf("%s", &fi);
    scanf("%s", &se);

    if (strlen(fi) <= 80 && strlen(se) <= 80) {
      for (j = strlen(fi) - 1, k = strlen(se) - 1, keta = 0, kuri = 0;
           j >= 0 || k >= 0; j--, k--, keta++) {
        if (j < 0)
          math1 = 0;
        else
          math1 = fi[j] - '0';
        if (k < 0)
          math2 = 0;
        else
          math2 = se[k] - '0';
        /*ans[keta]=((math1+math2+kuri)%10)+'0';*/
        kuri = (math1 + math2 + kuri) / 10;
      }
      if (kuri == 1)
        printf("1");
      if (keta - 1 <= 80) {
        for (j = keta - 1; j >= 0; j--) {
          printf("%c", ans[j]);
        }
      } else
        printf("overflow");
    } else
      printf("overflow");
    printf("\\n");
  }

  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

#define int long long

typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define each(it, v)                                                            \\
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
template <class T, class U> inline void chmin(T &t, U f) {
  if (t > f)
    t = f;
}
template <class T, class U> inline void chmax(T &t, U f) {
  if (t < f)
    t = f;
}

string s, t;
string ans;
int tmp[222222];

void solve() {
  cin >> s >> t;
  ans = string();
  reverse(all(s));
  reverse(all(t));
  if (s.size() < t.size())
    s += string(t.size() - s.size(), '0');
  if (t.size() < s.size())
    t += string(s.size() - t.size(), '0');

  memset(tmp, 0, sizeof(tmp));
  rep(i, s.size()) {
    tmp[i] += s[i] - '0' + t[i] - '0';
    tmp[i + 1] += tmp[i] / 10;
    tmp[i] %= 10;
  }

  rep(i, s.size()) { ans += string(1, '0' + tmp[i]); }
  if (tmp[s.size()])
    ans += string(1, '0' + tmp[s.size()]);
  reverse(all(ans));

  if (ans.size() > 80)
    cout << "overflow" << endl;
  else
    cout << ans << endl;
}

signed main() {
  int T;
  cin >> T;
  while (T--)
    solve();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

struct Integer {
  int num[100];
  Integer(char *s) {
    fill_n(num, 100, 0);
    int l = strlen(s);
    for (int i = 0; i < l; i++) {
      num[l - i - 1] = s[i] - '0';
    }
  }
};
const Integer operator+(const Integer &lint, const Integer &rint) {
  Integer ret("0");

  for (int i = 0; i < 100; i++) {
    int v = ret.num[i] + lint.num[i] + rint.num[i];
    ret.num[i] = v % 10;
    if (i + 1 >= 100)
      continue;
    ret.num[i + 1] += v / 10;
  }
  return ret;
}

char a[200], b[200];
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf("%s %s", a, b);
    Integer ans = Integer(a) + Integer(b);
    int s = 0;
    for (int i = 0; i < 100; i++)
      if (ans.num[i])
        s = i;
    if (s >= 80) {
      puts("overflow");
      continue;
    }
    for (int i = s; i >= 0; i--)
      printf("%d", ans.num[i]);
    puts("");
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int n, len, car;
  string a, b, ans;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    car = 0;
    ans = "";
    cin >> a >> b;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    len = max(a.length(), b.length());
    for (int i = 0; i < len; ++i) {
      int x, y, s;
      x = i < a.length() ? a[i] - '0' : 0;
      y = i < b.length() ? b[i] - '0' : 0;
      s = x + y + car;
      car = s / 10;
      ans += (s % 10 + '0');
    }
    if (car != 0)
      ans += (car + '0');
    if (ans.length() <= 80) {
      reverse(ans.begin(), ans.end());
      cout << ans << endl;
    } else {
      cout << "overflow" << endl;
    }
  }
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, c, res;
  bool f;
  string opr[2], buf;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    c = 0;
    f = false;
    for (int j = 0; j < 2; ++j) {
      cin >> buf;
      for (int k = 0; k < buf.length(); ++k)
        buf[k] = buf[k] - '0';
      opr[j].clear();
      for (int k = 0; k < 80 - buf.length(); ++k)
        opr[j] += (char)(0);
      opr[j] += buf;
    }
    for (int j = opr[0].length() - 1; 0 <= j; --j) {
      res = opr[0][j] + opr[1][j] + c;
      opr[0][j] = res % 10;
      c = res / 10;
    }
    if (!c) {
      for (int j = 0; j < opr[0].length(); ++j) {
        if (!f)
          f = opr[0][j] != 0;
        if (f)
          cout << (char)(opr[0][j] + '0');
      }
    } else
      cout << "overflow";
    cout << endl;
  }
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;
string add(string a, string b) {

  int numa[1001] = {0}, numb[1001] = {0};

  for (int i = a.size() - 1; i >= 0; i--)
    numa[a.size() - i - 1] = a[i] - '0';
  for (int i = b.size() - 1; i >= 0; i--)
    numb[b.size() - i - 1] = b[i] - '0';

  vector<int> renum(1001);

  fill(renum.begin(), renum.end(), 0);
  int mxsize = max(a.size(), b.size());

  for (int i = 0; i < mxsize; i++) {
    renum[i + 1] = (renum[i] + numa[i] + numb[i]) / 10;
    renum[i] = (renum[i] + numa[i] + numb[i]) % 10;
  }

  string srenum = "";
  for (int i = mxsize; i >= 0; i--) {
    if (i == mxsize && renum[i] == 0)
      continue;
    srenum += renum[i] + '0';
  }
  return srenum;
}

int main() {
  int n;
  cin >> n;
  while (n--) {
    string a, b;
    cin >> a >> b;
    a = add(a, b);
    if (a.size() > 80)
      cout << "overflow" << endl;
    else
      cout << a << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;
string add(string a, string b) {
  int numa[200] = {0}, numb[200] = {0};
  for (int i = a.size() - 1; i >= 0; i--)
    numa[a.size() - i - 1] = a[i] - '0';
  for (int i = b.size() - 1; i >= 0; i--)
    numb[b.size() - i - 1] = b[i] - '0';

  vector<int> renum(201);
  fill(renum.begin(), renum.end(), 0);
  int mxsize = max(a.size(), b.size());

  for (int i = 0; i < mxsize; i++) {
    renum[i + 1] = (renum[i] + numa[i] + numb[i]) / 10;
    renum[i] = (renum[i] + numa[i] + numb[i]) % 10;
  }

  string srenum = "";
  for (int i = mxsize; i >= 0; i--) {
    if (i == mxsize && renum[i] == 0)
      continue;
    srenum += renum[i] + '0';
  }
  return srenum;
}

int main() {
  int n;
  cin >> n;
  while (n--) {
    string a, b;
    cin >> a >> b;
    a = add(a, b);
    if (a.size() > 80)
      cout << "overflow" << endl;
    else
      cout << a << endl;
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {

    string num1, num2;
    cin >> num1 >> num2;

    if (num1.size() < num2.size())
      swap(num1, num2);
    if (num1.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    int m = num1.size() - num2.size();
    int M = num1.size();
    string n1 = "", n2 = "";
    for (int i = 0; i < m; i++)
      n2 += '0';
    n2 = n2 + num2;
    string nn1 = "", nn2 = "";
    for (int i = M - 1; i >= 0; i--) {
      nn1 += num1[i];
      nn2 += n2[i];
    }
    string ans = "", ansi = "";
    int t = 0;

    for (int i = 0; i < num1.size(); i++) {
      if (t + (nn1[i] - '0') + (nn2[i] - '0') >= 10) {
        ans += (t + (nn1[i] - '0') + (nn2[i] - '0') - 10) + '0';
        t = 1;
      } else {
        ans += (char)(t + (nn1[i] - '0') + (nn2[i] - '0') + '0');
        t = 0;
      }
    }

    if (t == 1)
      ans += '1';
    for (int i = ans.size() - 1; i >= 0; i--) {
      ansi += ans[i];
    }
    if (ansi.size() > 80) {
      cout << "overflow" << endl;
    } else
      cout << ansi << endl;
  }
  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  string num1, num2, tmp;
  int n;

  cin >> n;

  while (n--) {

    cin >> num1 >> num2;

    if ((int)num1.size() < (int)num2.size()) {
      tmp = num2;
      num2 = num1;
      num1 = tmp;
    }

    for (int i = 0; i < (int)num1.size(); i++)
      tmp[i] = num1[i];

    for (int i = (int)num1.size() - 1; i >= 0; i--) {
      num1[i] = tmp[(int)num1.size() - 1 - i];
    }
    for (int i = 0; i < (int)num2.size(); i++)
      tmp[i] = num2[i];

    for (int i = (int)num2.size() - 1; i >= 0; i--) {
      num2[i] = tmp[(int)num2.size() - 1 - i];
    }

    for (int i = (int)num2.size(); i < (int)num1.size(); i++)
      num2 += '0';

    char tmp2 = '0';
    string ans;

    for (int i = 0; i < num1.size(); i++) {
      if ((tmp2 - '0') + (num1[i] - '0') + (num2[i] - '0') > 9) {
        ans += (char)(((tmp2 - '0') + (num1[i] - '0') + (num2[i] - '0') - 10) +
                      '0');
        tmp2 = '1';
      } else {
        ans += (char)(((tmp2 - '0') + (num1[i] - '0') + (num2[i] - '0')) + '0');
        tmp2 = '0';
      }
    }

    if ((int)((tmp2 - '0') + (num1[num1.size() - 1] - '0') +
              (num2[num1.size() - 1] - '0')) > 9)
      ans += '1';

    for (int i = (int)ans.size(); i >= 0; i--) {
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}