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

#include <iostream>
#include <string>
#define MAX 80

using namespace std;

int main() {
  int n;
  cin >> n;
  for (int counter = 0; counter < n; counter++) {
    string a, b;
    cin >> a >> b;
    if (a.length() > MAX || b.length() > MAX) {
      cout << "overflow" << endl;
      continue;
    }
    if (a.length() == 1 && b.length() == 1 && a[0] == '0' && b[0] == '0') {
      cout << 0 << endl;
      continue;
    }
    int inta[MAX + 2], intb[MAX + 2], sum[MAX + 2];
    fill(inta, inta + MAX + 2, 0);
    fill(intb, intb + MAX + 2, 0);
    fill(sum, sum + MAX + 2, 0);
    for (int i = 0; i < (signed)a.length(); i++) {
      inta[i] = a[a.length() - i - 1] - '0';
    }
    for (int i = 0; i < (signed)b.length(); i++) {
      intb[i] = b[b.length() - i - 1] - '0';
    }

    int over = 0;
    for (int i = 0; i < MAX + 2; i++) {
      sum[i] = inta[i] + intb[i] + over;
      if (sum[i] >= 10) {
        sum[i] %= 10;
        over = 1;
      } else {
        over = 0;
      }
    }

    for (int i = MAX + 1;; i--) {
      if (sum[i] != 0) {
        if (i >= MAX) {
          cout << "overflow" << endl;
          break;
        }
        for (int j = i; j >= 0; j--) {
          cout << sum[j];
        }
        cout << endl;
        break;
      }
    }
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  for (int counter = 0; counter < n; counter++) {
    string a, b;
    cin >> a >> b;
    int inta[82], intb[82], sum[82];
    fill(inta, inta + 82, 0);
    fill(intb, intb + 82, 0);
    fill(sum, sum + 82, 0);
    for (int i = 0; i < (signed)a.length(); i++) {
      inta[i] = a[a.length() - i - 1] - '0';
    }
    for (int i = 0; i < (signed)b.length(); i++) {
      intb[i] = b[b.length() - i - 1] - '0';
    }

    int over = 0;
    for (int i = 0; i < 82; i++) {
      sum[i] = inta[i] + intb[i] + over;
      if (sum[i] >= 10) {
        sum[i] -= 10;
        over = 1;
      } else {
        over = 0;
      }
    }

    for (int i = 81;; i--) {
      if (sum[i] != 0) {
        for (int j = i; j >= 0; j--) {
          cout << sum[j];
        }
        cout << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

#define L 10
#define MAX 100000000
#define D 8

int main() {
  string s[2];
  int n, num[2][L], sum[L], dig[D + 1];
  for (int i = 0; i <= D; ++i)
    dig[i] = i ? 10 * dig[i - 1] : 1;
  cin >> n;
  while (n--) {
    cin >> s[0] >> s[1];
    if (s[0].length() > 80 || s[1].length() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < L; ++j)
        num[i][j] = 0;
      int len = s[i].length();
      for (int j = 0; j < len; ++j) {
        num[i][j / D] += dig[j % D] * (s[i][len - 1 - j] - '0');
        // cout << i << ", " << j << " "<< num[i][j/D] << endl;
      }
    }
    int carry = 0;
    for (int i = 0; i < L; ++i) {
      sum[i] = num[0][i] + num[1][i] + carry;
      carry = sum[i] / MAX;
      sum[i] %= MAX;
    }
    if (carry > 0) {
      cout << "overflow" << endl;
    } else {
      string ans;
      bool st = false;
      for (int i = L - 1; i >= 0; --i) {
        if (sum[i] == 0 && st) {
          ans += "00000000";
        } else if (sum[i] > 0) {
          for (int j = D - 1; j >= 0; --j) {
            int d = (sum[i] % dig[j + 1]) / dig[j];
            if (d > 0 || st) {
              ans += (char)(d + '0');
              st = true;
            }
          }
        }
      }
      cout << (ans.length() ? ans : "0") << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

typedef unsigned int uint;

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)

int main() {
  string str;
  int c, l, n;
  vector<int> dig[2], dig2(85, 0);
  cin >> n;
  while (n--) {
    for (int i = 0; i < 82; ++i)
      dig2[i] = 0;
    for (int i = 0; i < 2; ++i) {
      cin >> str;
      dig[i].clear();
      for (int j = (signed)str.length() - 1; j >= 0; --j)
        dig[i].push_back((int)(str[j] - '0'));
    }
    l = max(dig[0].size(), dig[1].size());
    c = 0;
    for (int i = 0; i < l; ++i) {
      dig2[i] = (i < dig[0].size() ? dig[0][i] : 0) +
                (i < dig[1].size() ? dig[1][i] : 0) + c;
      c = dig2[i] / 10;
      dig2[i] %= 10;
    }
    if (c) {
      dig2[l] = c;
      l++;
    }
    if (dig2[80] == 0) {
      for (int i = 0; i < l; ++i)
        cout << dig2[l - 1 - i];
      cout << endl;
    } else
      cout << "overflow" << endl;
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int tcase;

  cin >> tcase;
  while (tcase--) {
    string A, B, C = "";
    cin >> A >> B;

    unsigned sz = max(A.size(), B.size());
    while (A.size() < sz)
      A = '0' + A;
    while (B.size() < sz)
      B = '0' + B;

    int c = 0;
    for (int i = sz - 1; i >= 0; i--) {
      // answer
      C += (((A[i] - '0') + (B[i] - '0') + c) % 10 + '0');
      // carry
      c = ((A[i] - '0') + (B[i] - '0') + c) / 10;
    }
    if (c > 0)
      C += (c + '0');

    reverse(C.begin(), C.end());
    if (C.size() > 80)
      cout << "overflow" << endl;
    else
      cout << C << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n;
  scanf(" %d", &n);

  for (int i = 0; i < n; ++i) {
    char a[81], b[81], x[81], y[81];
    scanf(" %s %s", a, b);

    int LA = strlen(a);
    for (int i = 0; i < LA; ++i) {
      x[LA - 1 - i] = a[i];
    }
    int LB = strlen(b);
    for (int i = 0; i < LB; ++i) {
      y[LB - 1 - i] = b[i];
    }

    int big, small;
    bool isA;
    if (LA > LB) {
      big = LA;
      small = LB;
      isA = true;
    } else {
      big = LB;
      small = LA;
      isA = false;
    }

    char ans[81];
    int carry = 0;
    for (int i = 0; i < small; ++i) {
      int ta = x[i] - '0', tb = y[i] - '0';
      ta += tb + carry;

      if (ta >= 10)
        carry = 1;
      else
        carry = 0;
      ans[i] = (ta % 10) + '0';
    }
    if (isA) {
      for (int i = small; i < big; ++i) {
        int ta = x[i] - '0';
        ta += carry;

        if (ta >= 10)
          carry = 1;
        else
          carry = 0;
        ans[i] = (ta % 10) + '0';
      }
    } else {
      for (int i = small; i < big; ++i) {
        int tb = y[i] - '0';
        tb += carry;

        if (tb >= 10)
          carry = 1;
        else
          carry = 0;
        ans[i] = (tb % 10) + '0';
      }
    }

    if (big >= 80 && carry != 0)
      printf("overflow\\n");
    else {
      if (carry != 0) {
        ans[big++] = carry + '0';
        ans[big] = '\\0';
        // printf("carries\\n");
      }

      int LS = strlen(ans);
      char fans[82];
      for (int i = 0; i < LS; ++i) {
        fans[i] = ans[LS - 1 - i];
      }

      printf("%s\\n", fans);
    }
  }

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

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

int chomp(char *str) {
  int len = strlen(str);
  if (str[len - 1] == '\\n') {
    str[len - 1] = '\\0';
    len--;
  }
  return len;
}

int main() {
  int n;
  int i, j;
  int s1, s2, la, sm;
  char a1[102], a2[102], *pla, *psm, dummy[2];
  int carry, r;
  scanf("%d", &n);
  fgets(dummy, 2, stdin);
  for (i = 0; i < n; i++) {
    fgets(a1, 101, stdin);
    fgets(a2, 101, stdin);
    s1 = chomp(a1);
    s2 = chomp(a2);
    if (s1 > 80 || s2 > 80) {
      printf("overflow\\n");
      goto NEXT;
    }
    if (s1 < s2) {
      pla = a2;
      la = s2;
      psm = a1;
      sm = s1;
    } else {
      pla = a1;
      la = s1;
      psm = a2;
      sm = s2;
    }
    carry = 0;
    for (j = 0; j < la; j++) {
      r = (j < sm) ? (psm[sm - j - 1] - '0') : 0;
      r += (pla[la - j - 1] - '0') + carry;
      carry = r / 10;
      pla[la - j] = '0' + r % 10;
    }
    if (carry) {
      pla[0] = '1';
    } else {
      pla = (s1 < s2) ? &a2[1] : &a1[1];
    }
    if (j + carry > 80) {
      printf("overflow\\n");
      goto NEXT;
    }
    printf("%s\\n", pla);
  NEXT:
    printf("");
  }
}

Error: TLE

Fixed submission:

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

int chomp(char *str) {
  int len = strlen(str);
  if (str[len - 1] == '\\n') {
    str[len - 1] = '\\0';
    len--;
  }
  return len;
}

int main() {
  int n;
  int i, j;
  int s1, s2, la, sm;
  char a1[102], a2[102], *pla, *psm, dummy[2];
  int carry, r;
  scanf("%d", &n);
  fgets(dummy, 2, stdin);
  for (i = 0; i < n; i++) {
  NEXT:
    fgets(a1, 101, stdin);
    fgets(a2, 101, stdin);
    s1 = chomp(a1);
    s2 = chomp(a2);
    if (s1 > 80 || s2 > 80) {
      printf("overflow\\n");
      goto NEXT;
    }
    if (s1 < s2) {
      pla = a2;
      la = s2;
      psm = a1;
      sm = s1;
    } else {
      pla = a1;
      la = s1;
      psm = a2;
      sm = s2;
    }
    carry = 0;
    for (j = 0; j < la; j++) {
      r = (j < sm) ? (psm[sm - j - 1] - '0') : 0;
      r += (pla[la - j - 1] - '0') + carry;
      carry = r / 10;
      pla[la - j] = '0' + r % 10;
    }
    if (carry) {
      pla[0] = '1';
    } else {
      pla = (s1 < s2) ? &a2[1] : &a1[1];
    }
    if (j + carry > 80) {
      printf("overflow\\n");
      goto NEXT;
    }
    printf("%s\\n", pla);
  }
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  string str, str2;
  int ans_size, up, num;
  vector<int> ans;

  cin >> N;
  for (int n = 0; n < N; n++) {
    cin >> str >> str2;

    up = 0;
    for (int i = 0;; i++) {
      if (i >= str.size() && i >= str2.size()) {
        if (up > 0)
          ans.push_back(up);
        break;
      }
      num = 0;
      if (i < str.size())
        num += str[str.size() - 1 - i] - 48;
      if (i < str2.size())
        num += str2[str2.size() - 1 - i] - 48;
      ans.push_back((num + up) % 10);
      up = (num + up) / 10;
    }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

int main() {
  int N;
  char str1[90], str2[90];
  int num1[80], num2[80], sum[80];
  int pos, pos2, up;

  scanf("%d", &N);
  for (int n = 0; n < N; n++) {
    for (int i = 0; i < 90; i++) {
      str1[i] = 0;
      str2[i] = 0;
    }
    for (int i = 0; i < 80; i++) {
      num1[i] = 0;
      num2[i] = 0;
      sum[i] = 0;
    }
    scanf("%s", str1);
    scanf("%s", str2);

    pos = 89;
    while (pos >= 0 && str1[pos] == 0)
      pos--;
    pos2 = 0;
    while (pos >= 0 && pos2 < 80 && str1[pos] != 0) {
      num1[pos2] = str1[pos] - 48;
      pos2++;
      pos--;
    }
    pos = 89;
    while (pos >= 0 && str2[pos] == 0)
      pos--;
    pos2 = 0;
    while (pos >= 0 && pos2 < 80 && str2[pos] != 0) {
      num2[pos2] = str2[pos] - 48;
      pos2++;
      pos--;
    }

    /*for(int i = 0; i < 80; i++) printf("%d", num1[i]);
    printf("\\n");
    for(int i = 0; i < 80; i++) printf("%d", num2[i]);
    printf("\\n");*/

    up = 0;
    for (int i = 0; i < 80; i++) {
      sum[i] = num1[i] + num2[i] + up;
      up = sum[i] / 10;
      sum[i] = sum[i] % 10;
    }

    if (up > 0 || sum[79] > 0 || num1[79] > 0 || num2[79] > 0)
      printf("overflow\\n");
    else {
      pos = 79;
      while (pos >= 0 && sum[pos] == 0)
        pos--;
      if (pos < 0)
        printf("0");
      while (pos >= 0) {
        printf("%d", sum[pos]);
        pos--;
      }
      printf("\\n");
    }
  }

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

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

using namespace std;

int main(void) {
  int N;
  cin >> N;
  while (N--) {
    string s1, s2;
    cin >> s1;
    cin >> s2;
    vector<int> n1, n2, res;
    for (int i = s1.size(); i--;) {
      n1.push_back((int)(s1[i] - '0'));
    }
    for (int i = s2.size(); i--;) {
      n2.push_back((int)(s2[i] - '0'));
    }
    if (n1.size() < n2.size()) {
      for (int i = n1.size(); i < n2.size(); i++) {
        n1.push_back(0);
      }
    } else if (n2.size() < n1.size()) {
      for (int i = n2.size(); i < n1.size(); i++) {
        n2.push_back(0);
      }
    }
    int s, c = 0;
    for (int i = 0; i < n1.size(); i++) {
      s = n1[i] + n2[i] + c;
      res.push_back(s % 10);
      c = s / 10;
    }
    while (c != 0) {
      res.push_back(c % 10);
      c /= 10;
    }
    int size = res.size();
    while (size > 0 && res[size - 1] == 0) {
      size--;
    }
    if (size > 80) {
      cout << "overflow" << endl;
    } else {
      int i = res.size();
      while (i--) {
        cout << res[i];
      }
      cout << endl;
    }
  }
  return 0;
}

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


Fixed submission:

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

using namespace std;

int main(void) {
  int N;
  cin >> N;
  while (N--) {
    string s1, s2;
    cin >> s1;
    cin >> s2;
    vector<int> n1, n2, res;
    for (int i = s1.size(); i--;) {
      n1.push_back((int)(s1[i] - '0'));
    }
    for (int i = s2.size(); i--;) {
      n2.push_back((int)(s2[i] - '0'));
    }
    if (n1.size() < n2.size()) {
      for (int i = n1.size(); i < n2.size(); i++) {
        n1.push_back(0);
      }
    } else if (n2.size() < n1.size()) {
      for (int i = n2.size(); i < n1.size(); i++) {
        n2.push_back(0);
      }
    }
    int s, c = 0;
    for (int i = 0; i < n1.size(); i++) {
      s = n1[i] + n2[i] + c;
      res.push_back(s % 10);
      c = s / 10;
    }
    while (c != 0) {
      res.push_back(c % 10);
    }
    int size = res.size();
    while (size > 0 && res[size - 1] == 0) {
      size--;
    }
    if (size > 80) {
      cout << "overflow" << endl;
    } else {
      int i = size;
      while (i--) {
        cout << res[i];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repa(i, s, e) for (int i = s; i <= e; i++)
#define repd(i, s, e) for (int i = s; i >= e; i--)

typedef vector<int> vi;

int n;
string s1, s2;
char n1[80], n2[80], sum[80];

int main() {
  scanf("%d", &n);
  rep(i, n) {
    memset(n1, 0, sizeof(n1));
    memset(n2, 0, sizeof(n2));
    memset(sum, 0, sizeof(sum));

    cin >> s1 >> s2;
    int l1 = s1.size();
    int l2 = s2.size();
    if (max(l1, l2) > 80) {
      printf("overflow\\n");
      continue;
    }

    rep(k, l1) n1[k] = s1[l1 - k - 1] - '0';
    rep(k, l2) n2[k] = s2[l2 - k - 1] - '0';

    char a = 0;
    rep(i, 80) {
      char c = n1[i] + n2[i] + a;
      a = c / 10;
      sum[i] = c % 10;
    }

    if (a != 0) {
      printf("overflow\\n");
      continue;
    }

    bool start = false;
    repd(i, 79, 0) {
      if (sum[i] != 0)
        start = true;
      if (!start && sum[i] == 0)
        continue;
      printf("%d", sum[i]);
    }
    if (!start)
      printf("0");
    printf("\\n");
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repa(i, s, e) for (int i = s; i <= e; i++)
#define repd(i, s, e) for (int i = s; i >= e; i--)

typedef vector<int> vi;

int n;
string s1, s2;
char n1[81], n2[81], sum[81];

int main() {
  scanf("%d", &n);
  rep(i, n) {
    memset(n1, 0, sizeof(n1));
    memset(n2, 0, sizeof(n2));
    memset(sum, 0, sizeof(sum));

    cin >> s1 >> s2;
    int l1 = s1.size();
    int l2 = s2.size();
    if (min(l1, l2) > 80) {
      printf("overflow\\n");
      return 0;
    }

    rep(k, l1) n1[k] = s1[l1 - k - 1] - '0';
    rep(k, l2) n2[k] = s2[l2 - k - 1] - '0';

    char a = 0;
    rep(i, 80) {
      char c = n1[i] + n2[i] + a;
      a = c / 10;
      sum[i] = c % 10;
    }

    if (sum[80] != 0) {
      printf("overflow\\n");
      return 0;
    }

    bool start = false;
    repd(i, 80, 0) {
      if (sum[i] != 0)
        start = true;
      if (!start && sum[i] == 0)
        continue;
      printf("%d", sum[i]);
    }
    printf("\\n");
  }
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string a, b;
    cin >> a >> b;
    int sum, ret = 0;
    if (a.length() < b.length())
      swap(a, b);
    int l = b.length() - 1;
    for (int i = a.length() - 1; i >= 0; i--) {
      if (l >= 0) {
        sum = (a[i] - '0') + (b[l] - '0') + ret;
        l--;
      } else {
        sum = (a[i] - '0') + ret;
      }
      if (sum >= 10) {
        ret = 1;
        sum -= 10;
      } else {
        ret = 0;
      }
      a[i] = sum + '0';
    }
    if (ret != 0) {
      a.insert(a.begin(), ret + '0');
    }
    if (a.length() > 80)
      cout << "overflow" << endl;
    else
      cout << a << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#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;
    int sum, ret = 0;
    if (a.length() < b.length())
      swap(a, b);
    int l = b.length() - 1;
    for (int i = a.length() - 1; i >= 0; i--) {
      if (l >= 0) {
        sum = (a[i] - '0') + (b[l] - '0') + ret;
        l--;
      } else {
        sum = (a[i] - '0') + ret;
      }
      if (sum >= 10) {
        ret = 1;
        sum -= 10;
      } else {
        ret = 0;
      }
      c[i] = sum + '0';
    }
    if (ret != 0) {
      c.insert(a.begin(), ret + '0');
    }
    if (c.length() > 80)
      cout << "overflow" << endl;
    else
      cout << c << endl;
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <sstream>
#define NUM 100
using namespace std;

string error = "overflow";

int main() {
  int n;
  cin >> n;
  bool over[NUM];
  int keta[NUM];
  string a[NUM], b[NUM];
  char c[NUM][81];
  for (int i = 0; i < NUM; i++) {
    for (int j = 0; j < 81; j++) {
      c[i][j] = '0';
    }
  }
  for (int i = 0; i < n; i++) {
    over[i] = false;
    keta[i] = 0;
    int extra = 0;
    cin >> a[i] >> b[i];
    if (a[i].size() < b[i].size()) {
      swap(a[i], b[i]);
    }

    for (int j = 0; j < a[i].size(); j++) {
      int p, q, num;
      stringstream sa, sb, sc;
      sa << a[i][a[i].size() - j - 1];
      sa >> p;
      if (j < b[i].size()) {
        sb << b[i][b[i].size() - j - 1];
        sb >> q;
      } else {
        q = 0;
      }
      if (p + q + extra < 10) {
        sc << p + q + extra;
        sc >> c[i][j];
        extra = 0;
      } else {
        int kurai;
        kurai = (p + q + extra) % 10;
        sc << kurai;
        sc >> c[i][j];
        extra = 1;
        if (j == a[i].size() - 1) {
          c[i][a[i].size()] = '1';
          keta[i] = 1;
        }
      }
    }
    if (c[i][80] != '0') {
      over[i] = true;
    }
  }
  for (int i = 0; i < n; i++) {
    if (over[i] == true) {
      cout << error;
    } else {
      for (int j = 0; j < a[i].size() + keta[i]; j++) {
        cout << c[i][a[i].size() + keta[i] - j - 1];
      }
    }
    cout << endl;
  }
}

Error: 0

Fixed submission:

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

string error = "overflow";

int main() {
  int n;
  cin >> n;
  bool over[n];
  int keta[n];
  string a[n], b[n];
  char c[n][100];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 100; j++) {
      c[i][j] = '0';
    }
  }
  for (int i = 0; i < n; i++) {
    over[i] = false;
    keta[i] = 0;
    int extra = 0;
    cin >> a[i] >> b[i];
    if (a[i].size() < b[i].size()) {
      swap(a[i], b[i]);
    }

    for (int j = 0; j < a[i].size(); j++) {
      int p, q, num;
      stringstream sa, sb, sc;
      sa << a[i][a[i].size() - j - 1];
      sa >> p;
      if (j < b[i].size()) {
        sb << b[i][b[i].size() - j - 1];
        sb >> q;
      } else {
        q = 0;
      }
      if (p + q + extra < 10) {
        sc << p + q + extra;
        sc >> c[i][j];
        extra = 0;
      } else {
        int kurai;
        kurai = (p + q + extra) % 10;
        sc << kurai;
        sc >> c[i][j];
        extra = 1;
        if (j == a[i].size() - 1) {
          c[i][a[i].size()] = '1';
          keta[i] = 1;
        }
      }
    }
    if (c[i][80] != '0') {
      over[i] = true;
    }
  }
  for (int i = 0; i < n; i++) {
    if (over[i] == true) {
      cout << error;
    } else {
      for (int j = 0; j < a[i].size() + keta[i]; j++) {
        cout << c[i][a[i].size() + keta[i] - j - 1];
      }
    }
    cout << endl;
  }
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
#define MAX 1000
#define temp 85
int main() {
  int x, A[MAX], B[MAX], al, bl, sum[MAX], pre, now;
  char a[MAX], b[MAX];
  cin >> x;
  while (x-- > 0) {
    for (int i = 0; i < MAX; i++) {
      A[i] = 0;
      B[i] = 0;
      sum[i] = 0;
    }
    cin >> a;
    cin >> b;
    al = strlen(a);
    bl = strlen(b);
    for (int i = 0; i < al; i++)
      A[i] = a[al - 1 - i] - '0';
    for (int i = 0; i < bl; i++)
      B[i] = b[bl - 1 - i] - '0';
    if (al > bl)
      bl = al;
    pre = 0;
    for (int i = 0; i <= bl; i++) {
      if (A[i] + B[i] + pre > 9)
        now = 1;
      else
        now = 0;
      sum[i] = (A[i] + B[i] + pre) % 10;
      pre = now;
    }
    if (sum[bl] != 0) {
      if (bl >= 80) {
        cout << "overflow" << endl;
        continue;
      }
      for (int i = bl; i >= 0; i--)
        cout << sum[i];
    } else {
      if (bl - 1 >= 80) {
        cout << "overflow" << endl;
        ;
        continue;
      }
      for (int i = bl - 1; i >= 0; i--)
        cout << sum[i];
    }
    cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
#define MAX 100
#define temp 85
int main() {
  int x, A[MAX], B[MAX], al, bl, sum[MAX], pre, now;
  char a[MAX], b[MAX];
  cin >> x;
  while (x-- > 0) {
    for (int i = 0; i < MAX; i++) {
      A[i] = 0;
      B[i] = 0;
      sum[i] = 0;
    }
    cin >> a;
    cin >> b;
    al = strlen(a);
    bl = strlen(b);
    for (int i = 0; i < al; i++)
      A[i] = a[al - 1 - i] - '0';
    for (int i = 0; i < bl; i++)
      B[i] = b[bl - 1 - i] - '0';
    if (al > bl)
      bl = al;
    pre = 0;
    for (int i = 0; i <= bl; i++) {
      if (A[i] + B[i] + pre > 9)
        now = 1;
      else
        now = 0;
      sum[i] = (A[i] + B[i] + pre) % 10;
      pre = now;
    }

    if (sum[bl] != 0) {
      for (int i = bl; i >= 0; i--)
        cout << sum[i];
    } else {
      for (int i = bl - 1; i >= 0; i--)
        cout << sum[i];
    }

    cout << endl;
  }
  return 0;
}