alexjercan/bugnet huggingface dataset:
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <list>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    char c1[1000], c2[1000];
    scanf("%s", &c1);
    scanf("%s", &c2);
    string s1, s2;
    s1 = c1, s2 = c2;
    if (s1 == "0" && s2 == "0") {
      printf("0\\n");
      continue;
    }
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(), s2.end());
    int n = max(s1.size(), s2.size()) + 1;
    for (int i = s1.size(); i < n; i++) {
      s1 += '0';
    }
    for (int i = s2.size(); i < n; i++) {
      s2 += '0';
    }
    string res;
    int b = 0;
    for (int i = 0; i < max(s1.size(), s2.size()); i++) {
      int u = s1[i] - '0' + s2[i] - '0' + b;
      b = (u >= 10);
      u %= 10;
      res += u + '0';
    }

    reverse(res.begin(), res.end());
    string res2;
    int j = 0;
    while (res[j] == '0')
      j++;
    for (; j < res.size(); j++) {
      res2 += res[j];
    }

    if (res2.size() > 80) {
      printf("overflow\\n");
    } else {
      printf("%s\\n", res2.c_str());
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <list>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    char c1[80], c2[80];
    scanf("%s", &c1);
    scanf("%s", &c2);
    string s1, s2;
    s1 = c1, s2 = c2;
    if (s1 == "0" && s2 == "0") {
      printf("0\\n");
      continue;
    }
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(), s2.end());
    int n = max(s1.size(), s2.size()) + 1;
    for (int i = s1.size(); i < n; i++) {
      s1 += '0';
    }
    for (int i = s2.size(); i < n; i++) {
      s2 += '0';
    }
    string res;
    int b = 0;
    for (int i = 0; i < max(s1.size(), s2.size()); i++) {
      int u = s1[i] - '0' + s2[i] - '0' + b;
      b = (u >= 10);
      u %= 10;
      res += u + '0';
    }

    reverse(res.begin(), res.end());
    string res2;
    int j = 0;
    while (res[j] == '0')
      j++;
    for (; j < res.size(); j++) {
      res2 += res[j];
    }

    if (res2.size() > 80) {
      printf("overflow\\n");
    } else {
      printf("%s\\n", res2.c_str());
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int number_of_datasets;
  cin >> number_of_datasets;

  char A[81];
  char B[81];
  while (number_of_datasets-- > 0) {
    fill_n(A, 81, '\\0');
    fill_n(B, 81, '\\0');
    string input;
    cin >> input;
    if (input.length() > 80) {
      cin >> input;
      cout << "overflow" << endl;
      continue;
    }
    copy(input.rbegin(), input.rend(), A);
    cin >> input;
    if (input.length() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    copy(input.rbegin(), input.rend(), B);

    for (char &n : A) {
      if (n == '\\0') {
        break;
      }

      n -= '0';
    }

    for (char &n : B) {
      if (n == '\\0') {
        break;
      }

      n -= '0';
    }

    char carry = 0;
    for (int i = 0; i < 81; i++) {
      A[i] += B[i] + carry;
      if (A[i] >= 10) {
        A[i] -= 10;
        carry = 1;
      } else {
        carry = 0;
      }
    }

    if (A[80] != 0) {
      cout << "overflow";
    } else {
      int last_valid_place = 0;
      for (int i = 80; i >= 0; i--) {
        if (A[i] != 0) {
          last_valid_place = i;
          break;
        }
      }

      for (int i = last_valid_place; i >= 0; i--) {
        A[i] += '0';
        cout << A[i];
      }
    }

    cout << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int number_of_datasets;
  cin >> number_of_datasets;

  char A[81];
  char B[81];
  while (number_of_datasets--) {
    fill_n(A, 81, '\\0');
    fill_n(B, 81, '\\0');
    string input;
    cin >> input;
    copy(input.rbegin(), input.rend(), A);
    cin >> input;
    copy(input.rbegin(), input.rend(), B);

    for (char &n : A) {
      if (n == '\\0') {
        break;
      }

      n -= '0';
    }

    for (char &n : B) {
      if (n == '\\0') {
        break;
      }

      n -= '0';
    }

    char carry = 0;
    for (int i = 0; i < 81; i++) {
      A[i] += B[i] + carry;
      if (A[i] >= 10) {
        A[i] -= 10;
        carry = 1;
      } else {
        carry = 0;
      }
    }

    if (A[80] != 0) {
      cout << "overflow";
    } else {
      int last_valid_place = 0;
      for (int i = 80; i >= 0; i--) {
        if (A[i] != 0) {
          last_valid_place = i;
          break;
        }
      }

      for (int i = last_valid_place; i >= 0; i--) {
        A[i] += '0';
        cout << A[i];
      }
    }

    cout << endl;
  }
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
int max(int a, int b) { return a > b ? a : b; }
int main() {
  int n;
  scanf("%d", &n);
  for (int d = 0; d < n; d++) {
    char a[10000];
    char b[10000];
    scanf(" %s", a);
    scanf(" %s", b);
    if (strlen(a) > 80 || strlen(b) > 80) {
      printf("overflow\\n");
      continue;
    }
    string s, t;
    int i = 0;
    s.append(a);
    t.append(b);
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    string ans;
    int k = 0;
    for (i = 0; i < max(s.size(), t.size()) + 1; i++) {
      int x, y;
      if (i >= s.size())
        x = 0;
      else
        x = s[i] - '0';
      if (i >= t.size())
        y = 0;
      else
        y = t[i] - '0';
      int z = x + y + k;
      k = z / 10;
      char c = z % 10 + '0';
      if (i != max(s.size(), t.size()) || c != '0')
        ans.append(1, c);
    }
    reverse(ans.begin(), ans.end());
    if (ans.size() >= 81)
      printf("overflow\\n");
    else
      printf("%s\\n", ans.c_str());
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
#include <string>
using namespace std;
int max(int a, int b) { return a > b ? a : b; }
int main() {
  int n;
  scanf("%d", &n);
  for (int d = 0; d < n; d++) {
    char a[100];
    char b[100];
    scanf(" %s", a);
    scanf(" %s", b);
    string s, t;
    int i = 0;
    s.append(a);
    t.append(b);
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());
    string ans;
    int k = 0;
    for (i = 0; i < max(s.size(), t.size()) + 1; i++) {
      int x, y;
      if (i >= s.size())
        x = 0;
      else
        x = s[i] - '0';
      if (i >= t.size())
        y = 0;
      else
        y = t[i] - '0';
      int z = x + y + k;
      k = z / 10;
      char c = z % 10 + '0';
      if (i != max(s.size(), t.size()) || c != '0')
        ans.append(1, c);
    }
    reverse(ans.begin(), ans.end());
    if (ans.size() >= 81)
      printf("overflow\\n");
    else
      printf("%s\\n", ans.c_str());
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

#define debug(x) cout << #x << ": " << x << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

void solve() {
#ifdef _WIN32
  istream &cin = ifstream("input.txt");
#endif
  int n;
  cin >> n;
  rep(i, n) {
    vector<int> v1(101), v2(101);
    string s1, s2;
    cin >> s1 >> s2;

    rep(j, s1.size()) v1[j] = s1[s1.size() - j - 1] - '0';
    rep(j, s2.size()) v2[j] = s2[s2.size() - j - 1] - '0';

    rep(j, 100) {
      v1[j] += v2[j];
      if (v1[j] >= 10) {
        v1[j] -= 10;
        v1[j + 1]++;
      }
    }
    int digit = 0;
    for (int j = 100; j >= 0; j--) {
      if (v1[j] != 0) {
        digit = j;
        break;
      }
    }
    if (digit >= 80)
      cout << "overflow" << endl;
    else {
      for (int j = digit; j >= 0; j--)
        cout << v1[j];
      cout << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  solve();
  // system("PAUSE");
  return 0;
}

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


Fixed submission:

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

#define debug(x) cout << #x << ": " << x << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

void solve() {
  int n;
  cin >> n;
  rep(i, n) {
    vector<ll> v1(11), v2(11);
    string s1, s2;
    cin >> s1 >> s2;
    rep(j, 10) {
      if (s1.size() > 10 * j)
        v1[j] = stoi(s1.substr(
            10 * j, (s1.size() - 10 * j >= 10 ? 10 : s1.size() - 10 * j)));
      if (s2.size() > 10 * j)
        v2[j] = stoi(s2.substr(
            10 * j, (s2.size() - 10 * j >= 10 ? 10 : s2.size() - 10 * j)));
    }
    rep(j, 11) {
      v1[j] += v2[j];
      if (v1[j] >= 1e10) {
        v1[j] -= 1e10;
        v2[j]++;
      }
    }
    if (v1[8] || v1[9] || v1[10])
      cout << "overflow" << endl;
    else {
      rep(j, 11) if (v1[10 - j] != 0) cout << v1[10 - j];
      cout << endl;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  solve();
  // system("PAUSE");
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

#define MAX_SIZE 80

int main() {
  int n;
  cin >> n;

  string n1, n2;

  for (int i = 0; i < n; i++) {
    cin >> n1 >> n2;
    if (n1.size() > 80 || n2.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }

    // 先頭を0で埋めて80桁に合わせる
    char num1[MAX_SIZE], num2[MAX_SIZE];
    for (int i = n1.size(); i < 80; i++)
      n1.insert(0, "0");
    for (int i = n2.size(); i < 80; i++)
      n2.insert(0, "0");

    int c = 0;  // carry out
    char s = 0; // sum
    for (int i = 0; i < MAX_SIZE; i++) {
      s = n1.at(n1.size() - i - 1) + n2.at(n2.size() - i - 1) - 2 * '0' + c;
      // 桁上がりの有無
      if (s >= 10) {
        c = 1;
        s -= 10;
      } else {
        c = 0;
      }
      n1.at(n1.size() - i - 1) = s + '0';
    }

    if (c) {
      cout << "overflow" << endl;
    } else {
      while (n1.at(0) == '0' && n1.size() >= 2)
        n1.erase(0, 1); // 先頭の0を除く処理
      cout << n1 << endl;
    }

    n1.clear();
    n2.clear();
  }

  return 0;
}

Error: 0

Fixed submission:

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

#define MAX_SIZE 80

int main() {
  int n;
  cin >> n;

  string n1, n2;

  while (cin >> n1 >> n2) {

    if (n1.size() > 80 || n2.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }

    // 先頭を0で埋めて80桁に合わせる
    char num1[MAX_SIZE], num2[MAX_SIZE];
    for (int i = n1.size(); i < 80; i++)
      n1.insert(0, "0");
    for (int i = n2.size(); i < 80; i++)
      n2.insert(0, "0");

    int c = 0;  // carry out
    char s = 0; // sum
    for (int i = 0; i < MAX_SIZE; i++) {
      s = n1.at(n1.size() - i - 1) + n2.at(n2.size() - i - 1) - 2 * '0' + c;
      // 桁上がりの有無
      if (s >= 10) {
        c = 1;
        s -= 10;
      } else {
        c = 0;
      }
      n1.at(n1.size() - i - 1) = s + '0';
    }

    if (c) {
      cout << "overflow" << endl;
    } else {
      while (n1.at(0) == '0')
        n1.erase(0, 1); // 先頭の0を除く処理
      cout << n1 << endl;
    }

    n1.clear();
    n2.clear();
  }

  return 0;
}
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: WA

Fixed submission:

#include <iostream>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>

using namespace std;

int main() {

  string d;
  string e;

  int n = 0;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int f[81] = {0};
    int g[81] = {0};
    int h[81] = {0};

    cin >> d;
    cin >> e;

    int j = 81;
    for (int i = (int)d.length() - 1; i >= 0; i--) {
      f[j] = (d[i] - '0');
      j--;
    }
    j = 81;
    for (int i = (int)e.length() - 1; i >= 0; i--) {
      g[j] = (e[i] - '0');
      j--;
    }

    //        for(int i=0; i<=81; i++){
    //            printf("%d",f[i]);
    //        }
    //        printf("\\n");
    //
    //        for(int i=0; i<=81; i++){
    //            printf("%d",g[i]);
    //        }
    //        printf("\\n");

    int temp = 0;
    for (int i = 81; i >= 0; i--) {
      temp = temp + f[i] + g[i];
      h[i] = temp % 10;
      temp = temp / 10;
    }
    j = 0;
    while (h[j] == 0) {
      j++;
    }

    for (int i = j; i <= 81; i++) {
      printf("%d", h[i]);
    }
    printf("\\n");
  }
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string a, b;
  vector<int> ans;
  int n, num, ai, bi, c = 0;
  bool flag;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    flag = false;

    for (int j = 0; j < 100; j++) {
      num = 0;
      ai = a.size() - j - 1;
      bi = b.size() - j - 1;
      if (ai < 0 && bi < 0 && c == 0)
        break;

      if (ai >= 0)
        num += a[ai] - 48;
      if (bi >= 0)
        num += b[bi] - 48;
      ans.push_back((num + c) % 10);
      if (num + c >= 10)
        c = 1;
      else
        c = 0;
    }
    if (ans.size() > 80) {
      flag = true;
    }
    if (flag) {
      printf("overflow");
    } else {
      for (int j = ans.size() - 1; j >= 0; --j) {
        printf("%d", ans[j]);
      }
    }
    printf("\\n");
    ans.clear();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define REP(i, a, b) for ((i) = (a); (i) < (int)(b); (i)++)
#define rep(i, n) REP(i, 0, n)
// BEGIN CUT HERE
#define foreach(itr, c)                                                        \\
  for (typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
// END CUT HERE

int main() {
  int i, n;

  cin >> n;
  while (n--) {
    int fix = 0;
    string s1, s2, tmp, res;

    cin >> s1;
    if ((int)s1.size() > 80)
      fix++;
    cin >> s2;
    if ((int)s2.size() > 80)
      fix++;

    vector<int> a(100, 0);
    rep(i, s1.size()) a[i] = s1[(int)s1.size() - 1 - i] - '0';
    vector<int> b(100, 0);
    rep(i, s2.size()) b[i] = s2[(int)s2.size() - 1 - i] - '0';

    rep(i, 100) {
      int sum = a[i] + b[i];
      if (sum >= 10) {
        sum %= 10;
        a[i + 1]++;
      }
      tmp += sum + '0';
    }

    reverse(tmp.begin(), tmp.end());
    bool f = false;
    rep(i, tmp.size()) {
      if (tmp[i] != '0')
        f = true;
      if (f)
        res += tmp[i];
    }

    if ((int)res.size() > 80)
      fix++;
    if (fix)
      cout << "overflow" << endl;
    else
      cout << res << endl;
  }

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

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

int main() {
  int n;
  string up, un;
  cin >> n;
  while (n--) {
    cin >> up >> un;
    if (up.size() > 80 || un.size() > 80) {
    exit:
      cout << "overflow\\n";
      continue;
    }
    if (up.size() < un.size())
      swap(up, un);
    for (int i = up.size() - 1, j = un.size() - 1; i >= 0; i--, j--) {
      if (j >= 0)
        up[i] += un[j] - '0';
      if (up[i] > '9') {
        up[i] -= 10;
        if (i == 0)
          up = "1" + up;
        else
          up[i - 1]++;
      }
    }
    if (up.size() > 80)
      goto exit;
    cout << up << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int j;
  int n;
  char s1[111];
  char tmp[111];
  char s2[111];
  char ans[111];
  int kuri = 0;
  cin >> n;
  while (n--) {
    memset(ans, 0, sizeof(ans));
    memset(s1, 0, sizeof(s1));
    memset(s2, 0, sizeof(s2));
    memset(tmp, 0, sizeof(tmp));
    cin >> s1 >> s2;
    if (strlen(s1) > 80 || strlen(s2) > 80) {
      cout << "overflow" << endl;
    } else if (strlen(s1) < strlen(s2)) {
      for (int i = 0, j = strlen(s1) - 1; i <= j; i++, j--)
        swap(s1[i], s1[j]);
      for (int i = 0, j = strlen(s2) - 1; i <= j; i++, j--)
        swap(s2[i], s2[j]);
      for (int i = 0; i < strlen(s2); i++) {
        if ((s2[i] + (s1[i] % '0') + kuri) > '9') {
          ans[i] = (s2[i] + (s1[i] % '0') + kuri) - 10;
          kuri = 1;
        } else {
          ans[i] = (s2[i] + (s1[i] % '0') + kuri);
          kuri = 0;
        }
        if (i == strlen(s2) - 1 && kuri == 1)
          ans[i + 1] = '1';
      }
      if (strlen(ans) > 80)
        cout << "overflow" << endl;
      else {
        for (int i = strlen(ans) - 1; i >= 0; i--)
          cout << ans[i];
      }
    } else {
      for (int i = 0, j = strlen(s1) - 1; i <= j; i++, j--)
        swap(s1[i], s1[j]);
      for (int i = 0, j = strlen(s2) - 1; i <= j; i++, j--)
        swap(s2[i], s2[j]);
      for (int i = 0; i < strlen(s1); i++) {
        if ((s1[i] + (s2[i] % '0') + kuri) > '9') {
          ans[i] = (s1[i] + (s2[i] % '0') + kuri) - 10;
          kuri = 1;
        } else {
          ans[i] = (s1[i] + (s2[i] % '0') + kuri);
          kuri = 0;
        }
        if (i == strlen(s1) - 1 && kuri == 1)
          ans[i + 1] = '1';
      }
      if (strlen(ans) > 80)
        cout << "overflow" << endl;
      else {
        for (int i = strlen(ans) - 1; i >= 0; i--)
          cout << ans[i];
      }
    }
    cout << endl;
  }
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int i, j, k;
  for (i = 0; i < N; ++i) {

    int digits[2][80];
    for (j = 0; j < 2; ++j) {
      for (k = 0; k < 80; ++k) {
        digits[j][k] = 0;
      }
    }

    int overflow = 0;

    for (j = 0; j < 2; ++j) {
      char digit[256];
      scanf("%256s", digit);
      getchar();

      if (overflow || strlen(digit) > 80) {
        overflow = 1;
      } else {
        for (k = 0; k < strlen(digit); ++k) {
          digits[j][k] = digit[strlen(digit) - 1 - k] - '0';
        }
      }
    }

    if (!overflow) {
      int sum[81];
      for (j = 0; j < 81; ++j) {
        sum[j] = 0;
      }

      for (j = 0; j < 80; ++j) {
        for (k = 0; k < 2; ++k) {
          sum[j] += digits[k][j];
        }
        sum[j + 1] += sum[j] / 10;
        sum[j] %= 10;
      }

      if (sum[80] > 0) {
        overflow = 1;
      } else {
        int available = 0;
        for (j = 80; j >= 0; --j) {
          if (available || sum[j] != 0 || j == 0) {
            available = 1;
            printf("%d", sum[j]);
          }
        }
        printf("\\n");
      }
    }

    if (overflow) {
      printf("overflow\\n");
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

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

  int i, j, k;
  for (i = 0; i < N; ++i) {

    int digits[2][80];
    for (j = 0; j < 2; ++j) {
      for (k = 0; k < 80; ++k) {
        digits[j][k] = 0;
      }
    }

    int overflow = 0;

    for (j = 0; j < 2; ++j) {
      char digit[256];
      scanf("%s", digit);
      getchar();

      if (overflow || strlen(digit) > 80) {
        overflow = 1;
      } else {
        for (k = 0; k < strlen(digit); ++k) {
          digits[j][k] = digit[strlen(digit) - 1 - k] - '0';
        }
      }
    }

    if (!overflow) {
      int sum[81];
      for (j = 0; j < 81; ++j) {
        sum[j] = 0;
      }

      for (j = 0; j < 80; ++j) {
        for (k = 0; k < 2; ++k) {
          sum[j] += digits[k][j];
        }
        sum[j + 1] += sum[j] / 10;
        sum[j] %= 10;
      }

      if (sum[80] > 0) {
        overflow = 1;
      } else {
        int available = 0;
        for (j = 80; j >= 0; --j) {
          if (available || sum[j] != 0 || j == 0) {
            available = 1;
            printf("%d", sum[j]);
          }
        }
        printf("\\n");
      }
    }

    if (overflow) {
      printf("overflow\\n");
    }
  }

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n, maxlen;
  char a[10001], b[10001];

  cin >> n;
  for (int ii = 0; ii < n; ii++) {
    string ans = "";
    scanf("%s %s", a, b);

    maxlen = max(strlen(a), strlen(b));

    reverse(a, a + strlen(a));
    reverse(b, b + strlen(b));

    for (int i = strlen(a); i < 10001; i++) {
      a[i] = '0';
    }
    for (int i = strlen(b); i < 10001; i++) {
      b[i] = '0';
    }

    int tmp, tmp2 = 0;

    for (int i = 0; i < maxlen; i++) {
      tmp = (a[i] - '0') + (b[i] - '0') + tmp2;

      if (i == maxlen - 1) {
        if (tmp >= 10) {
          tmp2 = 1;
          tmp -= 10;
          ans += tmp + '0';
          ans += '1';
        } else
          ans += tmp + '0';
      }

      else if (tmp >= 10) {
        tmp2 = 1;
        tmp -= 10;
        ans += tmp + '0';
      } else if (tmp <= 9) {
        ans += tmp + '0';
        tmp2 = 0;
      }
    }

    reverse(ans.begin(), ans.end());

    int size = ans.size();

    if (size > 80 || maxlen > 80)
      cout << "overflow" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n, maxlen;
  char a[101], b[101];

  cin >> n;
  for (int ii = 0; ii < n; ii++) {
    string ans = "";
    scanf("%s%s", a, b);

    maxlen = max(strlen(a), strlen(b));

    reverse(a, a + strlen(a));
    reverse(b, b + strlen(b));

    for (int i = strlen(a); i < 100; i++) {
      a[i] = '0';
    }
    for (int i = strlen(b); i < 100; i++) {
      b[i] = '0';
    }

    int tmp, tmp2 = 0;
    bool flag = 0;

    for (int i = 0; i < maxlen; i++) {
      tmp = (a[i] - '0') + (b[i] - '0') + tmp2;

      if (i == maxlen - 1) {
        if (tmp >= 10) {
          tmp2 = 1;
          tmp -= 10;
          ans += tmp + '0';
          ans += '1';
        } else
          ans += tmp + '0';
      }

      else if (tmp >= 10) {
        tmp2 = 1;
        tmp -= 10;
        ans += tmp + '0';
      } else if (tmp <= 9) {
        ans += tmp + '0';
        tmp2 = 0;
      }
    }

    reverse(ans.begin(), ans.end());

    int size = ans.size();

    if (size >= 80 || maxlen >= 80)
      cout << "overflow" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}