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

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

void calcSum(string str1, string str2) {
  int c = 0;
  string str = "";
  if (str1.size() > str2.size()) {
    swap(str1, str2);
  }
  for (int i = 0; i < (int)str1.size(); i++) {
    int sum = (str1[i] - '0') + (str2[i] - '0') + c;
    if (sum >= 10) {
      str += (sum % 10) + '0';
      c = 1;
    } else {
      str += sum + '0';
      c = 0;
    }
  }
  for (int i = (int)str1.size(); i < (int)str2.size(); i++) {
    int sum = (str2[i] - '0') + c;
    if (sum >= 10) {
      str += (sum % 10) + '0';
      c = 1;
    } else {
      str += sum + '0';
      c = 0;
    }
  }
  if (c == 1)
    str += '1';
  reverse(str.begin(), str.end());
  if (str.size() > 80) {
    cout << "overflow" << endl;
  } else {
    cout << str << endl;
  }
}

int main() {
  int n;
  string str1, str2;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str1;
    cin >> str2;
    reverse(str1.begin(), str1.end());
    reverse(str2.begin(), str2.end());
    calcSum(str1, str2);
  }

  return 0;
}

Error: WA

Fixed submission:

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

void storeReverse(char ch[], string str) {
  for (int i = 0; i < str.size(); i++) {
    ch[i] = str[str.size() - i - 1];
  }
}

void calcSum(char ch1[], char ch2[]) {
  int c = 0;
  int result[80];
  for (int i = 0; i < 80; i++) {
    int num1 = ch1[i] - '0';
    int num2 = ch2[i] - '0';
    int sum = num1 + num2 + c;
    if (sum >= 10) {
      sum %= 10;
      c = 1;
    } else {
      c = 0;
    }
    result[i] = sum;
  }
  if (c == 1) {
    cout << "overflow" << endl;
  } else {
    int idx;
    for (int i = 80 - 1; i >= 0; i--) {
      if (result[i] != 0) {
        idx = i;
        break;
      }
    }
    for (int i = idx; i >= 0; i--) {
      cout << result[i];
    }
    cout << endl;
  }
}

int main() {
  int n;
  char ch1[80], ch2[80];
  string str1, str2;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str1;
    cin >> str2;
    for (int j = 0; j < 80; j++) {
      ch1[j] = '0';
      ch2[j] = '0';
    }
    storeReverse(ch1, str1);
    storeReverse(ch2, str2);
    calcSum(ch1, ch2);
  }

  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  string s, t, u;
  int n;
  char ch;

  cin >> n;
  for (int loop = 0; loop < n; loop++) {
    cin >> s >> t;

    //    cout << "\\ns=" << s << endl << "t=" <<  t << endl;

    if (s.length() > 80 || t.length() > 80) {
      cout << "overflow" << endl;
      continue;
    }

    while (s.length() > t.length())
      t = "0" + t;
    while (t.length() > s.length())
      s = "0" + s;
    /*
    cout << "s=" << s << " len=" << s.length() << endl;
    cout << "t=" << t << " len=" << t.length() << endl;
    */
    u = "";
    int c = 0;
    for (int i = s.length() - 1; i >= 0; --i) {
      int a = s[i] - '0';
      int b = t[i] - '0';
      int sum = a + b + c;
      if (sum >= 10) {
        sum -= 10;
        c = 1;
      } else
        c = 0;
      ch = sum + '0';
      u = ch + u;
    }
    if (c == 1)
      u = "1" + u;

    if (u.length() > 80)
      cout << "overflow" << endl;
    else
      cout << u << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define N 256
using namespace std;

void pr(vector<int> a) {
  int i = 0;
  while (a[i] == 0)
    i++;

  for (; i < a.size(); i++)
    cout << a[i];
  cout << endl;
}

int main() {
  char s[100], c;
  vector<int> a, b;
  int n, an, bn, len;
  cin >> n;
  fgets(s, N, stdin);
  for (int loop = 0; loop < n; loop++) {
    a.clear();
    fgets(s, N, stdin);

    for (int i = 0; s[i] != '\\n'; i++)
      a.push_back(s[i] - '0');
    b.clear();
    fgets(s, N, stdin);
    for (int i = 0; s[i] != '\\n'; i++)
      b.push_back(s[i] - '0');
    an = a.size();
    bn = b.size();
    while (an > bn) {
      b.insert(b.begin(), 1, 0);
      bn++;
    }
    while (an < bn) {
      a.insert(a.begin(), 1, 0);
      an++;
    }

    //    pr(a);
    //    pr(b);
    a.insert(a.begin(), 1, 0);
    b.insert(b.begin(), 1, 0);
    for (int i = an; i >= 0; i--) {
      a[i] += b[i];
      if (a[i] >= 10) {
        a[i] -= 10;
        a[i - 1]++;
      }
    }
    pr(a);
  }

  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int N = 85;

char a[N], b[N];

void reverse(char a[]) {
  int len = strlen(a);
  for (int i = 0, j = len - 1; i < j; ++i, --j) {
    char tmp = a[i];
    a[i] = a[j];
    a[j] = tmp;
  }
}

void add(char a[], char b[]) {
  int lenA = strlen(a);
  int lenB = strlen(b);
  int i, j, tmp, jin = 0;
  for (i = 0; i < lenA && i < lenB; ++i) {
    tmp = (a[i] - '0') + (b[i] - '0') + jin;
    a[i] = tmp % 10 + '0';
    jin = tmp / 10;
  }
  if (!a[i] && !b[i] && jin) {
    a[lenA] = jin + '0';
    a[lenA + 1] = '\\0';
  } else if (a[i] && !b[i]) {
    for (; i < lenA; ++i) {
      tmp = a[i] - '0' + jin;
      a[i] = tmp % 10 + '0';
      jin = tmp / 10;
    }
    if (jin) {
      a[lenA] = jin + '0';
      a[lenA + 1] = '\\0';
    }
  } else if (!a[i] && b[i]) {
    for (; i < lenB; ++i) {
      tmp = b[i] - '0' + jin;
      a[i] = tmp % 10 + '0';
      jin = tmp / 10;
    }
    if (jin) {
      a[lenB] = jin + '0';
      a[lenB + 1] = '\\0';
    } else
      a[lenB] = '\\0';
  }
}

int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s%s", a, b);
    if (strlen(a) > 80 || strlen(b) > 80)
      printf("overflow\\n");
    else {
      reverse(a);
      reverse(b);
      add(a, b);
      if (strlen(a) > 80)
        printf("overflow\\n");
      else
        reverse(a), printf("%s\\n", a);
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int N = 85;

char a[N], b[N];

void reverse(char a[]) {
  int len = strlen(a);
  for (int i = 0, j = len - 1; i < j; ++i, --j) {
    char tmp = a[i];
    a[i] = a[j];
    a[j] = tmp;
  }
}

void add(char a[], char b[]) {
  int lenA = strlen(a);
  int lenB = strlen(b);
  int i, j, tmp, jin = 0;
  for (i = 0; i < lenA && i < lenB; ++i) {
    tmp = (a[i] - '0') + (b[i] - '0') + jin;
    a[i] = tmp % 10 + '0';
    jin = tmp / 10;
  }
  if (!a[i] && !b[i] && jin) {
    a[lenA] = jin + '0';
    a[lenA + 1] = '\\0';
  } else if (a[i] && !b[i] && jin) {
    for (; i < lenA; ++i) {
      tmp = a[i] - '0' + jin;
      a[i] = tmp % 10 + '0';
      jin = tmp / 10;
    }
    if (jin) {
      a[lenA] = jin + '0';
      a[lenA + 1] = '\\0';
    }
  } else if (!a[i] && b[i] && jin) {
    for (; i < lenB; ++i) {
      tmp = b[i] - '0' + jin;
      a[i] = tmp % 10 + '0';
      jin = tmp / 10;
    }
    if (jin) {
      a[lenB] = jin + '0';
      a[lenB + 1] = '\\0';
    } else
      a[lenB] = '\\0';
  }
}

int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%s%s", a, b);
    if (strlen(a) > 80 || strlen(b) > 80)
      printf("overflow\\n");
    else {
      reverse(a);
      reverse(b);
      add(a, b);
      if (strlen(a) > 80)
        printf("overflow\\n");
      else
        reverse(a), printf("%s\\n", a);
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>
int main(void) {
  int ap, bp, cp, t;
  char a[999], b[999], c[82];
  scanf("%d", &t);
  while (~scanf("%s%s", &a, &b)) {
    ap = strlen(a);
    bp = strlen(b);
    c[cp = (ap > 80 || bp > 80) ? 0 : 81] = '\\0';
    t = 0;
    while ((t || ap || bp) && cp > 0) {
      t += (ap ? a[--ap] - '0' : 0) + (bp ? b[--bp] - '0' : 0);
      c[--cp] = '0' + t % 10;
      t /= 10;
    }
    if (cp > 0)
      puts(&c[cp]);
    else
      puts("overflow");
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
#include <string.h>
int main(void) {
  int n, ap, bp, cp, t;
  char a[81], b[81], c[81];
  scanf("%d", &n);
  while (~scanf("%s%s", &a, &b)) {
    ap = strlen(a);
    bp = strlen(b);
    cp = sizeof(c) - 1;
    c[cp] = '\\0';
    t = 0;
    while ((t || ap || bp) && cp > 0) {
      t += (ap ? a[--ap] - '0' : 0) + (bp ? b[--bp] - '0' : 0);
      c[--cp] = '0' + (t % 10);
      t /= 10;
    }
    if (t)
      printf("overflow\\n");
    else
      printf("%s\\n", &c[cp]);
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
using namespace std;
int a[110], b[110], c[110];
char x[110], y[110];
void ff(char z[110]) {
  int d = strlen(z);
  for (int i = 0; i < d / 2; i++) {
    swap(z[i], z[d - 1 - i]);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));
    scanf("%s", x);
    scanf("%s", y);
    ff(x), ff(y);
    if (strlen(x) > 80 || strlen(y) > 80) {
      printf("overflow\\n");
      continue;
    }

    for (int i = 0; i < strlen(x); i++) {
      a[i] = x[i] - '0';
    }
    for (int i = 0; i < strlen(y); i++) {
      b[i] = y[i] - '0';
    }
    int d = 0, s;
    for (int i = 0; i < 110; i++) {
      s = a[i] + b[i] + d;
      c[i] = s % 10;
      d = s / 10;
    }
    int p = 0;
    for (int i = 109; i >= 0; i--) {
      if (c[i]) {
        p = i;
        break;
      }
    }
    if (p >= 80) {
      printf("overflow\\n");
      continue;
    }

    for (int i = p; i >= 0; i--) {
      printf("%d", c[i]);
    }
    printf("\\n");
  }
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int A[90], B[90], C[90];

int main() {
  int n;
  cin >> n;
  while (n > 0) {
    n--;
    string str1, str2;
    cin >> str1 >> str2;
    int len1 = str1.length();
    int len2 = str2.length();
    if (len1 < len2) {
      string st = str1;
      str1 = str2;
      str2 = st;
      int ll = len1;
      len1 = len2;
      len2 = ll;
    }
    for (int i = 0; i < 90; i++)
      C[i] = 0;
    for (int i = 0; i < len1; i++)
      A[i] = str1[len1 - 1 - i] - '0';
    for (int i = 0; i < len2; i++)
      B[i] = str2[len2 - 1 - i] - '0';
    for (int i = 0; i < len2; i++) {
      C[i] = (A[i] + B[i]) % 10;
      C[i + 1] = (A[i] + B[i]) / 10;
    }
    for (int i = len2; i < len1; i++) {
      C[i] = C[i] + A[i];
      C[i + 1] = C[i] / 10;
      C[i] = C[i] % 10;
    }

    if (C[80] > 0)
      cout << "overflow" << endl;
    else {
      if (C[len1] > 0)
        len1++;
      for (int i = len1 - 1; i >= 0; i--)
        cout << C[i];
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>

using namespace std;

int A[1000], B[1000], C[1000];

int main() {
  int n;
  cin >> n;
  while (n > 0) {
    n--;
    string str1, str2;
    cin >> str1 >> str2;
    int len1 = str1.length();
    int len2 = str2.length();
    if (len1 < len2) {
      string st = str1;
      str1 = str2;
      str2 = st;
      int ll = len1;
      len1 = len2;
      len2 = ll;
    }
    for (int i = 0; i < 1000; i++) {
      C[i] = 0;
      A[i] = 0;
      B[i] = 0;
    }

    for (int i = 0; i < len1; i++)
      A[i] = str1[len1 - 1 - i] - '0';
    for (int i = 0; i < len2; i++)
      B[i] = str2[len2 - 1 - i] - '0';
    for (int i = 0; i < len1; i++) {
      C[i] = A[i] + B[i] + C[i];
      C[i + 1] = C[i] / 10;
      C[i] = C[i] % 10;
    }
    // for(int i = len2; i <len1; i++)
    // {
    //  C[i] = C[i] + A[i];
    //  C[i+1] = C[i] / 10;
    //   C[i] = C[i] % 10;
    // }

    if (C[80] > 0)
      cout << "overflow" << endl;
    else {
      if (C[len1] > 0)
        len1++;
      for (int i = len1 - 1; i >= 0; i--)
        cout << C[i];
      cout << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int A[95], B[95], C[95];

int main() {
  int n;
  cin >> n;
  while (n > 0) {
    n--;
    string str1, str2;
    cin >> str1 >> str2;
    int len1 = str1.length();
    int len2 = str2.length();
    if (len1 < len2) {
      string st = str1;
      str1 = str2;
      str2 = st;
      int ll = len1;
      len1 = len2;
      len2 = ll;
    }
    for (int i = 0; i < 90; i++) {
      C[i] = 0;
      A[i] = 0;
      B[i] = 0;
    }

    for (int i = 0; i < len1; i++)
      A[i] = str1[len1 - 1 - i] - '0';
    for (int i = 0; i < len2; i++)
      B[i] = str2[len2 - 1 - i] - '0';
    for (int i = 0; i < len1; i++) {
      C[i] = A[i] + B[i] + C[i];
      C[i + 1] = C[i] / 10;
      C[i] = C[i] % 10;
    }
    // for(int i = len2; i <len1; i++)
    // {
    //  C[i] = C[i] + A[i];
    //  C[i+1] = C[i] / 10;
    //   C[i] = C[i] % 10;
    // }

    if (C[80] > 0)
      cout << "overflow" << endl;
    else {
      if (C[len1] > 0)
        len1++;
      for (int i = len1 - 1; i >= 0; i--)
        cout << C[i];
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

int a[85], b[85];

int reverse(int *p, int length) {
  int i, t;

  for (i = 1; i <= length / 2; i++) {
    t = p[i];
    p[i] = p[length + 1 - i];
    p[length + 1 - i] = t;
  }

  return 0;
}

int main() {
  int N, i, la, lb, lmax, carry, t;
  char ch;

  scanf("%d%*c", &N);

  while (N--) {
    la = 0;
    lb = 0;
    carry = 0;
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));

    while (1) {
      ch = getchar();

      if (ch >= '0' && ch <= '9') {
        la++;
        a[la] = ch - '0';
      }

      else if (ch == '\\n') {
        break;
      }
    }

    while (1) {
      ch = getchar();

      if (ch >= '0' && ch <= '9') {
        lb++;
        b[lb] = ch - '0';
      }

      else if (ch == '\\n') {
        break;
      }
    }

    if (la > 80 || lb > 80) {
      printf("overflow\\n");
      continue;
    }

    reverse(a, la);
    reverse(b, lb);

    lmax = la > lb ? la : lb;

    for (i = 1; i <= lmax + 1; i++) {
      t = a[i];
      a[i] = (t + b[i] + carry) % 10;
      carry = (t + b[i] + carry) / 10;
    }

    for (i = lmax + 1; i >= 1; i--) {
      if (a[i] != 0) {
        t = i;
        break;
      }
    }

    if (t > 80) {
      printf("overflow\\n");
      continue;
    }

    if (i == 0) {
      printf("0\\n");
      continue;
    }

    for (i = t; i >= 1; i--) {
      printf("%d", a[i]);
    }

    printf("\\n");
  }

  return 0;
}

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


Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int chrtoint(char a) {
  int i;
  i = a - 48;
  return i;
  return 0;
}

int main() {
  char n1[80];
  char n2[80];
  int rs[80];
  int c1, c2;

  int i, j, m, cmax, sum, testcase;
  scanf("%d", &testcase);
  while (testcase--) {
    scanf("%s", &n1);
    scanf("%s", &n2);
    c1 = strlen(n1);
    c2 = strlen(n2);

    reverse(n1, n1 + c1);
    reverse(n2, n2 + c2);

    cmax = c1;
    if (c1 < c2) {
      cmax = c2;
    }

    m = 0;
    for (i = 0; i < cmax; i++) {
      if (c1 == c2 || (i < c1 && i < c2)) {
        sum = m + chrtoint(n1[i]) + chrtoint(n2[i]);
      } else if (i >= c1) {
        sum = m + chrtoint(n2[i]);
      } else if (i >= c2) {
        sum = m + chrtoint(n1[i]);
      }
      if (sum > 9) {
        m = 1;
        rs[i] = sum - 10;
      } else {
        m = 0;
        rs[i] = sum;
      }
    }

    if (m) {
      rs[i] = m;
      i++;
    }
    if (i > 80) {
      printf("overflow\\n");
      continue;
    }
    for (j = 0; j < i; j++) {
      printf("%d", rs[i - j - 1]);
    }
  }
  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;
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    if (A.size() > 80 || B.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    for (int i = 0; i < A.size() || i < B.size(); i++) {
      int n = 0;
      if (i < A.size())
        n += (A[i] - '0');
      if (i < B.size())
        n += (B[i] - '0');
      C.push_back(n);
    }
    C.resize(C.size() + 1);
    C[C.size() - 1] = 0;
    for (int i = 0; i < C.size(); i++) {
      if (i != C.size() - 1)
        C[i + 1] += C[i] / 10, C[i] %= 10;
    }
    if (C[C.size() - 1] == 0) {
      C.resize(C.size() - 1);
    }
    reverse(C.begin(), C.end());
    if (C.size() > 80) {
      cout << "overflow" << endl;
    } else {
      for (int i = 0; i < C.size(); i++) {
        cout << (char)(C[i] + '0');
      }
      cout << endl;
    }
  }
}

Error: WA

Fixed submission:

#include <cstdio>
#include <cstring>
char A[81], B[81], C[84];
int main() {
  int N, Alen, Blen;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", A);
    scanf("%s", B);
    Alen = strlen(A);
    Blen = strlen(B);
    memset(C, -1, sizeof(C));
    for (int j = Alen - 1, k = 0; j >= 0; j--, k++) {
      C[k] = A[j] - '0';
    }
    for (int j = Blen - 1, k = 0; j >= 0; j--, k++) {
      C[k] += B[j] - '0';
    }
    for (int j = 0; C[j] != -1; j++) {
      if (C[j] / 10) {
        if (C[j + 1] != -1)
          C[j + 1] += C[j] / 10;
        else
          C[j + 1] = C[j] / 10;
      }
      C[j] %= 10;
    }
    for (int j = 82; j >= 0; j--) {
      if (C[j] != -1) {
        if (j > 80) {
          printf("overflow");
          break;
        }
        putchar('0' + C[j]);
      }
    }
    putchar('\\n');
  }
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a[128], b[128], r[128];
    fill(a, a + 128, 0);
    fill(b, b + 128, 0);
    fill(r, r + 128, 0);
    string sa, sb;
    cin >> sa >> sb;
    reverse(sa.begin(), sa.end());
    reverse(sb.begin(), sb.end());
    for (unsigned int j = 0; j < min(128, int(sa.length())); j++)
      a[j] = sa[j] - '0';
    for (unsigned int j = 0; j < min(128, int(sb.length())); j++)
      b[j] = sb[j] - '0';
    for (int j = 0; j <= 80; j++) {
      r[j] += a[j] + b[j];
      r[j + 1] += r[j] / 10;
      r[j] %= 10;
    }
    if (r[80])
      cout << "overflow" << endl;
    else {
      int k = 79;
      for (; k >= 1 && !r[k]; k--)
        ;
      for (int j = k; j >= 0; j--)
        cout << r[j];
      cout << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a[80], b[80], r[81];
    fill(a, a + 80, 0);
    fill(b, b + 80, 0);
    fill(r, r + 81, 0);
    string sa, sb;
    cin >> sa >> sb;
    reverse(sa.begin(), sa.end());
    reverse(sb.begin(), sb.end());
    for (unsigned int j = 0; j < sa.length(); j++)
      a[j] = sa[j] - '0';
    for (unsigned int j = 0; j < sb.length(); j++)
      b[j] = sb[j] - '0';
    for (int j = 0; j < 80; j++) {
      r[j] += a[j] + b[j];
      r[j + 1] += r[j] / 10;
      r[j] %= 10;
    }
    if (r[80])
      cout << "overflow" << endl;
    else {
      int k = 79;
      for (; k >= 1 && !r[k]; k--)
        ;
      for (int j = k; j >= 0; j--)
        cout << r[j];
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a[80];
    string sa1, sa2, s1 = "", s2 = "";
    for (int i = 0; i < 80; i++)
      a[i] = 0;
    cin >> sa1 >> sa2;
    if (sa1.length() > 80 || sa2.length() > 80) {
      printf("overflow\\n");
      continue;
    }
    for (int j = 0; j < 80 - sa1.length(); j++) {
      s1 += '0';
    }
    s1 += sa1;
    for (int j = 0; j < 80 - sa2.length(); j++) {
      s2 += '0';
    }
    s2 += sa2;
    for (int i = 0; i < 80; i++) {
      a[i] += (s1[i] - '0') + (s2[i] - '0');
    }
    for (int i = 79; i >= 1; i--) {
      a[i - 1] += a[i] / 10;
      a[i] %= 10;
    }
    if (a[0] >= 10) {
      printf("overflow\\n");
      continue;
    }
    int x = 0;
    while (a[x] == 0)
      x++;
    for (int i = x; i <= 79; i++) {
      cout << a[i];
    }
    if (x == 80)
      printf("0\\n");
    else
      printf("\\n");
  }
  return 0;
}

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


Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a[80];
    string sa1, sa2, s1 = "", s2 = "";
    for (int i = 0; i < 80; i++)
      a[i] = 0;
    cin >> sa1 >> sa2;
    for (int j = 0; j < 80 - sa1.length(); j++) {
      s1 += '0';
    }
    s1 += sa1;
    for (int j = 0; j < 80 - sa2.length(); j++) {
      s2 += '0';
    }
    s2 += sa2;
    for (int i = 0; i < 80; i++) {
      a[i] += (s1[i] - '0') + (s2[i] - '0');
    }
    for (int i = 79; i >= 1; i--) {
      a[i - 1] += a[i] / 10;
      a[i] %= 10;
    }
    if (a[0] >= 10) {
      printf("overflow\\n");
      continue;
    }
    int x = 0;
    while (a[x] == 0)
      x++;
    for (int i = x; i <= 79; i++) {
      cout << a[i];
    }
    if (x == 80)
      printf("0\\n");
    else
      printf("\\n");
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    // char s[100] = "abc";
    string a, b;

    cin >> a >> b;
    if (a == b) {
      if (a == "0") {
        cout << "0" << endl;
        continue;
      }
    }
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    while (a.size() < 100)
      a += "0";
    while (b.size() < 100)
      b += "0";
    string ans = "";
    int carry = 0;
    for (int i = 0; i < 100; i++) {
      int d = (a[i] - '0') + (b[i] - '0') + carry;
      ans += d % 10 + '0';
      carry = d / 10;
    }
    reverse(ans.begin(), ans.end());
    if (ans.find_first_not_of('0') < 20) {
      cout << "overflow" << endl;
      continue;
    }
    ans = ans.substr(ans.find_first_not_of('0'));

    cout << ans << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    // char s[100] = "abc";
    string a, b;

    cin >> a >> b;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    while (a.size() < 100)
      a += "0";
    while (b.size() < 100)
      b += "0";
    string ans = "";
    int carry = 0;
    for (int i = 0; i < 100; i++) {
      int d = (a[i] - '0') + (b[i] - '0') + carry;
      ans += d % 10 + '0';
      carry = d / 10;
    }
    reverse(ans.begin(), ans.end());
    if (ans.find_first_not_of('0') < 20) {
      cout << "overflow" << endl;
      continue;
    }
    ans = ans.substr(ans.find_first_not_of('0'));

    cout << ans << endl;
  }

  return 0;
}