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

#include <stdio.h>
#include <string.h>
int main(void) {
  int n;
  scanf("%d", &n);
  while (n--) {
    char a[1000], b[1000], c[1000];
    int j, len;

    for (j = 0; j < 81; j++) {
      a[j] = 0;
      b[j] = 0;
      c[j] = '0';
    }
    scanf("%s%s", a, b);
    len = strlen(a);
    if (len < strlen(b))
      len = strlen(b);
    if (len > 80) {
      printf("overflow\\n");
      continue;
    }
    /*for(j=0;j<len+1;j++){
       c[j]='0';9999999999999999999999999999999999999999999999999999999999999999999999999999999
    }*/
    for (j = 0; j < strlen(a); j++) {
      c[j] = a[strlen(a) - j - 1];
    }
    for (j = 0; j < strlen(b); j++) {
      c[j] += b[strlen(b) - j - 1] - '0';
    }
    for (j = 0; j < len; j++) {
      if (c[j] >= 58) {
        if (j == len - 1) {
          c[j + 1] = '0';
          len++;
        }
        c[j] -= 10;
        c[j + 1] += 1;
      };
    }
    if (len > 80) {
      printf("overflow\\n");
      continue;
    } else {
      for (j = len - 1; j >= 0; j--) {
        printf("%c", c[j]);
      }
      puts("");
    }
  }
  return 0;
}

// 9999999999999999999999999999999999999999999999999999999999999999999999999999999

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
int main(void) {
  int n;
  scanf("%d", &n);
  while (n--) {
    char a[100], b[100], c[100];
    int j, len;

    for (j = 0; j < 81; j++) {
      a[j] = 0;
      b[j] = 0;
      c[j] = '0';
    }
    scanf("%s%s", a, b);
    len = strlen(a);
    if (len < strlen(b))
      len = strlen(b);
    if (len > 80) {
      printf("overflow\\n");
      continue;
    }
    /*for(j=0;j<len+1;j++){
       c[j]='0';9999999999999999999999999999999999999999999999999999999999999999999999999999999
    }*/
    for (j = 0; j < strlen(a); j++) {
      c[j] = a[strlen(a) - j - 1];
    }
    for (j = 0; j < strlen(b); j++) {
      c[j] += b[strlen(b) - j - 1] - '0';
    }
    for (j = 0; j < len; j++) {
      if (c[j] >= 58) {
        if (j == len - 1) {
          c[j + 1] = '0';
          len++;
        }
        c[j] -= 10;
        c[j + 1] += 1;
      };
    }
    if (len > 80) {
      printf("overflow\\n");
      continue;
    } else {
      for (j = len - 1; j >= 0; j--) {
        printf("%c", c[j]);
      }
      puts("");
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    string one, two, ans;
    cin >> one >> two;
    int os = one.size() - 1, ts = two.size() - 1;
    int ls = (os > ts) ? os : ts;
    int t = 0;
    for (int i = 0; i <= ls; i++) {
      if (i <= os && i <= ts) {
        t = one[os - i] + two[ts - i] - '0' * 2 + t / 10;
      } else if (i <= os) {
        t = one[os - i] - '0' + t / 10;
      } else if (i <= ts) {
        t = two[ts - i] - '0' + t / 10;
      }
      ans += (t % 10) + '0';
    }
    if (t / 10) {
      ans += '1';
    }
    if (ans.size() > 80) {
      cout << "overflow" << endl;
    } else {
      for (int i = ans.size() - 1; i >= 0; i--) {
        cout << ans[i];
      }
      cout << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  cin.ignore();
  while (n--) {
    string one;
    string two;
    string ans[200];
    getline(cin, one);
    getline(cin, two);
    int os = one.size() - 1, ts = two.size() - 1;
    int ls = max(os, ts), ss = min(os, ts);
    int as = 0, x, t = 0;
    for (int i = 0; i <= ls; i++) {
      if (i <= os && i <= ts) {
        x = one[os - i] + two[ts - i] - '0' * 2 + t;
      } else if (i <= os) {
        x = one[os - i] - '0' + t;
      } else if (i <= ts) {
        x = two[ts - i] - '0' + t;
      }
      t = x / 10;
      x = x % 10;
      ans[i] = x + '0';
      as++;
    }
    if (t > 0) {
      ans[as + 1] = t + '0';
      as++;
    }
    if (as >= 80) {
      cout << "overflow" << endl;
    } else {
      for (int i = as; i >= 0; i--) {
        cout << ans[i];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error


#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring> //strlen
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

bool solve() {

  //	なぜかわからないがstirngだと数字が大きいとSegmentation fault
  /*
          string str1,str2;
          cin>> str1>> str2;
          int n1 = str1.size();
          int n2 = str2.size();
  */
  char str1[10000], str2[10000];
  scanf("%s %s", str1, str2);
  int n1 = strlen(str1);
  int n2 = strlen(str2);

  int n = max(n1, n2);

  /*	string str="";
   */
  char str[10000];
  int c = 0;
  int i = 0;
  while (i < n) {
    int a = c;
    if (i < n1) {
      a += (str1[n1 - i - 1] - '0');
    }
    if (i < n2) {
      a += (str2[n2 - i - 1] - '0');
    }
    c = a / 10;
    a = a % 10;

    str[i] = a + '0';
    i++;
  }
  if (c) {
    str[i] = c + '0';
    i++;
  }

  if (i >= 81) {
    cout << "overflow" << endl;
    return true;
  }

  for (int j = i - 1; j >= 0; j--) {
    cout << str[j];
  }
  cout << endl;

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(5);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    solve();
  }
  return 0;
}


Error: WA

Fixed submission:


#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring> //strlen
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

bool solve() {

  //	なぜかわからないがstirngだと数字が大きいとSegmentation fault
  /*
          string str1,str2;
          cin>> str1>> str2;
          int n1 = str1.size();
          int n2 = str2.size();
  */
  char str1[100], str2[100];
  scanf("%s %s", str1, str2);
  int n1 = strlen(str1);
  int n2 = strlen(str2);

  int n = max(n1, n2);

  /*	string str="";
   */
  char str[1000];
  int c = 0;
  int i = 0;
  while (i < n) {
    int a = c;
    if (i < n1) {
      a += (str1[n1 - i - 1] - '0');
    }
    if (i < n2) {
      a += (str2[n2 - i - 1] - '0');
    }
    c = a / 10;
    a = a % 10;

    str[i] = a + '0';
    i++;
  }
  if (c) {
    str[i] = c + '0';
    i++;
  }

  if (i > 81) {
    cout << "overflow" << endl;
    return true;
  }

  for (int j = i - 1; j >= 0; j--) {
    cout << str[j];
  }
  cout << endl;

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(5);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    solve();
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <iterator>
#include <stddef.h>
#include <string>

using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s1, s2, s3 = "";
    cin >> s1 >> s2;
    size_t m = max(s1.size(), s2.size());
    while (s1.size() < m)
      s1.insert(s1.begin(), '0');
    while (s2.size() < m)
      s2.insert(s2.begin(), '0');
    char c = 0;
    auto it1 = s1.rbegin();
    auto it2 = s2.rbegin();
    for (; it1 != s1.rend(); it1++, it2++) {
      char add = *it1 - '0' + *it2 - '0' + c;
      char ch = add % 10 + '0';
      c = add / 10;
      s3.insert(s3.begin(), ch);
    }
    if (c)
      s3.insert(s3.begin(), c + '0');
    cout << ((s3.size() > 80) ? "overflow" : s3) << endl;
  }
}

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


Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.14159265358979
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <vector>
using namespace std;

int main() {
  int n;
  string x, y;
  int a, b, c;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x.length() > 80 || y.length() > 80) {
      cout << "overflow" << endl;
    } else {
      a = stoi(x);
      b = stoi(y);
      if (to_string(a + b).length() > 80) {
        cout << "overflow" << endl;
      } else
        cout << a + b << endl;
    }
  }
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

string hissan(string a, string b) {
  if (a.size() < b.size())
    a.swap(b);
  int bi = b.size() - 1;
  int c = 0;
  string ans;

  for (int i = a.size() - 1; i >= 0; i--) {
    int _a = a[i] - '0';
    int _b = (bi >= 0) ? b[bi--] - '0' : 0;
    int x = _a + _b + c;

    if (x < 10) {
      c = 0;
    } else {
      x -= 10;
      c = 1;
    }
    ans.insert(0, to_string(x));
  }

  if (c)
    ans.insert(0, "1");

  return ans;
}

int main() {
  int n;
  string a, b;

  cin >> n;
  while (n--) {
    cin >> a;
    cin >> b;
    string x = hissan(a, b);
    cout << ((x.size() > 80) ? "overflow" : x) << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int sum(char a[], char b[], int as, int bs, char c[]) {
  int cs = (as > bs) ? as + 1 : bs + 1;
  int size = cs;
  while (as >= 0 && bs >= 0) {
    c[cs] += a[as] + b[bs];
    if (c[cs] > 9) {
      c[cs] -= 10;
      c[cs - 1] += 1;
    }
    as--;
    bs--;
    cs--;
  }
  while (as >= 0) {
    c[cs] += a[as];
    if (c[cs] > 9) {
      c[cs] -= 10;
      c[cs - 1] += 1;
    }
    as--;
    cs--;
  }
  while (bs >= 0) {
    c[cs] += b[bs--];
    if (c[cs] > 9) {
      c[cs] -= 10;
      c[cs - 1] += 1;
    }
    cs--;
  }
  return (c[0] > 0) ? size + 1 : size;
}

int main() {
  char a[256], b[256], c[256];
  bool flag = true;
  int len1, len2, len3, n;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", a);
    scanf("%s", b);
    len1 = strlen(a);
    len2 = strlen(b);
    if (len1 > 80 || len2 > 80) {
      printf("overflow\\n");
      continue;
    }
    for (int i = 0; i < len1; i++)
      a[i] -= 0x30;
    for (int i = 0; i < len2; i++)
      b[i] -= 0x30;
    for (int i = 0; i < 256; i++)
      c[i] = 0;
    len3 = sum(a, b, len1 - 1, len2 - 1, c);
    if (len3 > 80) {
      printf("overflow\\n");
      continue;
    }
    if (c[0] > 0)
      for (int i = 0; i < len3; i++)
        printf("%d", c[i]);
    else
      for (int i = 1; i <= len3; i++)
        printf("%d", c[i]);
    printf("\\n");
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int DIGIT = 9;

int main() {
  int n;
  char buf[82];
  int l, x[2], y, z;
  char buf_part[DIGIT + 1];
  int a[2][9];
  int b[9];
  bool overflow_flg;

  cin >> n;
  while (n--) {
    overflow_flg = false;
    for (int i = 0; i < 2; i++) {
      fscanf(stdin, "%81s", buf);
      l = strlen(buf);
      if (l > 80) {
        overflow_flg = true;
        while (getchar() != '\\n')
          ;
        continue;
      }
      x[i] = (l + DIGIT - 1) / DIGIT;
      y = (l - 1) % DIGIT + 1;
      for (int j = 0; j < 9; j++) {
        a[i][j] = 0;
      }
      for (int j = 0; j < x[i]; j++) {
        if (!j) {
          memcpy(buf_part, buf, y);
          buf_part[y] = '\\0';
        } else {
          memcpy(buf_part, &buf[y + DIGIT * (j - 1)], DIGIT);
          buf_part[DIGIT] = '\\0';
        }
        a[i][x[i] - j - 1] = atoi(buf_part);
      }
    }
    if (overflow_flg) {
      cout << "overflow" << endl;
      continue;
    }

    for (int i = 0; i < 9; i++)
      b[i] = 0;
    z = (x[0] > x[1]) ? x[0] : x[1];
    for (int i = 0; i < z; i++) {
      b[i] = a[0][i] + a[1][i];
      if (b[i] >= 1000000000) {
        a[0][i + 1]++;
        b[i] -= 1000000000;
      }
    }
    if (z < 9 && a[0][z]) {
      b[z] = a[0][z] + a[1][z];
      ++z;
    }
    if (b[8] >= 100000000) {
      cout << "overflow" << endl;
    } else {
      cout << b[z - 1];
      for (int i = z - 2; i >= 0; i--) {
        cout.fill('0');
        cout.width(DIGIT);
        cout << b[i];
      }
      cout << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int DIGIT = 9;

int main() {
  int n;
  char buf[81];
  int l, x[2], y, z;
  char buf_part[DIGIT + 1];
  int a[2][9];
  int b[9];

  cin >> n;
  while (n--) {
    for (int i = 0; i < 2; i++) {
      cin >> buf;
      l = strlen(buf);
      x[i] = (l + DIGIT - 1) / DIGIT;
      y = (l - 1) % DIGIT + 1;
      for (int j = 0; j < 9; j++) {
        a[i][j] = 0;
      }
      for (int j = 0; j < x[i]; j++) {
        if (!j) {
          memcpy(buf_part, buf, y);
          buf_part[y] = '\\0';
        } else {
          memcpy(buf_part, &buf[y + DIGIT * (j - 1)], DIGIT);
          buf_part[DIGIT] = '\\0';
        }
        a[i][x[i] - j - 1] = atoi(buf_part);
      }
    }

    /*for (int i=0; i<9; i++) b[i] = 0;
    z = (x[0] > x[1]) ? x[0] : x[1];
    for (int i=0; i<z; i++) {
      b[i] = a[0][i] + a[1][i];
      if (b[i] >= 1000000000) {
        a[0][i+1]++;
        b[i] -= 1000000000;
      }
    }
    if (z<9 && a[0][z]) {
      b[z] = a[0][z]+a[1][z];
      ++z;
    }
    if (b[8] >= 100000000) {
      cout << "overflow" << endl;
    } else {
      cout << b[z-1];
      for (int i=z-2; i>=0; i--) {
        cout.fill('0');
        cout.width(DIGIT);
        cout << b[i];
      }
      cout << endl;
    }*/
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, m;
  string aindex, bindex, ans;
  cin >> m;
  n = 0;
  string a, b;
  for (int j = 0; j < m; j++) {
    cin >> a >> b;
    if (a.size() > 80 || b.size() > 80) {
      cout << "overflow" << endl;
    } else {
      for (int i = 0; i < max(a.size(), b.size()); i++) {
        if (a.size() >= i + 1) {
          aindex = a[a.size() - i - 1];
        } else {
          aindex = "0";
        }
        if (b.size() >= i + 1) {
          bindex = b[b.size() - i - 1];
        } else {
          bindex = "0";
        }
        n = stoi(aindex) + stoi(bindex) + (n - n % 10 == 10);
        aindex = to_string(n % 10);
        ans = aindex + ans;
      }

      if (n - n % 10 == 10) {
        ans = '1' + ans;
      }

      if (ans.size() > 80) {
        cout << "overflow" << endl;
      } else {
        cout << ans << endl;
      }
    }
    ans = "";
    n = 0;
  }
  return 0;
}

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


Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, m;
  string aindex, bindex, ans;
  cin >> m;
  n = 0;
  string a, b;
  for (int j = 0; j < m; j++) {
    cin >> a >> b;
    if (a.size() > 80 || b.size() > 80) {
      cout << "overflow" << endl;
    } else {
      for (int i = 0; i < max(a.size(), b.size()); i++) {
        if (a.size() - i > 0) {
          aindex = a[a.size() - i - 1];
        } else {
          aindex = "0";
        }
        if (b.size() - i > 0) {
          bindex = b[b.size() - i - 1];
        } else {
          bindex = "0";
        }
        n = stoi(aindex) + stoi(bindex) + (n - n % 10 == 10);
        aindex = to_string(n % 10);
        ans = aindex + ans;
      }
      if (ans.size() > 80) {
        cout << "overflow" << endl;
      } else {
        cout << ans << endl;
      }
    }
  }
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
int main() {
  int n;
  cin >> n;
  while (n--) {
    string a, b;
    int x[84], y[84], s[84], max;
    cin >> a >> b;
    if (a.length() > 80 || b.length() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    int i = 0, j = 0;
    for (; a[i] != '\\0'; ++i) {
      x[i] = a[i] - '0';
    }
    for (; b[j] != '\\0'; ++j) {
      y[j] = b[j] - '0';
    }

    if (i > j) {
      for (int k = j - 1; k >= 0; k--) {
        y[i - j + k] = y[k];
      }
      rep(k, i - j) { y[k] = 0; }
      max = i;
    } else if (i < j) {
      for (int k = i - 1; k >= 0; k--) {
        x[j - i + k] = x[k];
      }
      rep(k, j - i) { x[k] = 0; }
      max = j;
    } else
      max = i;
    bool f = 0;
    for (int k = max - 1; k >= 0; k--) {
      int c = x[k] + y[k];
      if (f)
        c++;
      if (c >= 10) {
        f = 1, c -= 10;
      } else
        f = 0;
      s[k] = c;
    }
    if (f) {
      max++;
    }
    if (max > 80)
      cout << "overflow" << endl;
    else {
      string ans;
      if (f) {
        ans += "1";
        max--;
      }
      rep(k, max) { ans += s[k] + '0'; }
      cout << ans << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

#define rep2(x, from, to) for (int x = (from); (x) < (to); (x)++)
#define rep(x, to) rep2(x, 0, to)
int main() {
  int n;
  cin >> n;
  while (n--) {
    char a[84], b[84];
    int x[84], y[84], s[84], max;
    cin >> a >> b;
    int i = 0, j = 0;
    for (; a[i] != '\\0'; ++i) {
      x[i] = a[i] - '0';
    }
    for (; b[j] != '\\0'; ++j) {
      y[j] = b[j] - '0';
    }
    if (i > j) {
      for (int k = j - 1; k >= 0; k--) {
        y[i - j + k] = y[k];
      }
      rep(k, i - j) { y[k] = 0; }
      max = i;
    } else if (i < j) {
      for (int k = i - 1; k >= 0; k--) {
        x[j - i + k] = x[k];
      }
      rep(k, j - i) { x[k] = 0; }
      max = j;
    }
    bool f = 0;
    for (int k = max - 1; k >= 0; k--) {
      int c = x[k] + y[k];
      if (f)
        c++;
      if (c >= 10) {
        f = 1, c -= 10;
      } else
        f = 0;
      s[k] = c;
    }
    if (f) {
      max++;
    }
    if (max > 80)
      cout << "overflow" << endl;
    else {
      if (f) {
        cout << 1;
        max--;
      }
      rep(k, max) { cout << s[k]; }
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main() {
  int N;
  cin >> N;
  while (N--) {
    string s1, s2;
    cin >> s1 >> s2;

    if (s1.size() > 80 || s2.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    char buf[81] = {0};
    int p1 = s1.size() - 1, p2 = s2.size() - 1, pb = 79;
    int carry = 0;
    while (p2 >= 0)
      buf[pb--] = s2[p2--];
    pb = 79;
    while (pb >= 0 && (p1 >= 0 || carry > 0)) {
      int bd = buf[pb];
      if (bd > 0)
        bd -= '0';
      int bp = 0;
      if (p1 >= 0)
        bp = s1[p1--] - '0';
      int d = bp + bd + carry;
      carry = d / 10;
      d %= 10;
      buf[pb--] = d + '0';
    }
    while (pb >= 0 && buf[pb])
      pb--;
    if (pb == -1 && carry > 0)
      cout << "overflow" << endl;
    else
      cout << (char *)(buf + (pb + 1)) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

string add(string a, string b) {
  string res;
  int sa = a.size();
  int sb = b.size();
  int va, vb, t = 0;
  for (int i = 1; i <= max(sa, sb); i++) {
    if (sa - i < 0)
      va = 0;
    else
      va = a[sa - i] - '0';
    if (sb - i < 0)
      vb = 0;
    else
      vb = b[sb - i] - '0';
    if (t)
      va++;
    t = ((va + vb) > 9);
    res = (char)(va + vb - t * 10 + '0') + res;
  }
  if (t)
    res = "1" + res;
  return res;
}

int main() {
  int n;
  cin >> n;
  while (n) {
    string a, b;
    string ans;
    cin >> a >> b;
    ans = add(a, b);
    if (ans.size() > 80) {
      cout << "overflow" << endl;
    } else {
      cout << ans << endl;
    }
  }
  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 s1, s2;
    int l1, l2;
    cin >> s1 >> s2;
    l1 = s1.length();
    l2 = s2.length();
    if (l1 > 80 || l2 > 80)
      cout << "overflow";
    else {
      int result[100], r = 0, m = max(l1, l2), t;
      reverse(s1.begin(), s1.end());
      reverse(s2.begin(), s2.end());
      s1.resize(m + 1, '0');
      s2.resize(m + 1, '0');
      for (int j = 0; j < m; j++) {
        t = r + s1[j] + s2[j] - 48 * 2;
        result[j] = t % 10;
        r = t / 10;
      }
      if (r == 1)
        result[m++] = 1;
      if (m > 80)
        cout << "overflow";
      else
        for (int j = m - 1; j >= 0; j--)
          cout << result[j];
    }
    cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s1, s2;
    int l1, l2;
    cin >> s1 >> s2;
    l1 = s1.length();
    l2 = s2.length();
    if (l1 > 80 || l2 > 80)
      cout << "overflow" << endl;
    else {
      int result[100], r = 0, m = max(l1, l2);
      reverse(s1.begin(), s1.end());
      reverse(s2.begin(), s2.end());
      for (int j = 0; j < m; j++) {
        if (s1[j] == NULL)
          s1[j] = '0';
        if (s2[j] == NULL)
          s2[j] = '0';
        int t = s1[j] + s2[j] - 48 * 2;
        result[j] = r + t % 10;
        r = t / 10;
      }
      if (r == 1)
        result[m++] = 1;
      for (int j = m - 1; j >= 0; j--)
        cout << result[j];
    }
    cout << endl;
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define ALL(v) v.begin(), v.end()
string calc(string a, string b) {
  reverse(ALL(a));
  reverse(ALL(b));
  while (a.size() < b.size())
    a += '0';
  while (b.size() < a.size())
    b += '0';
  int c = 0;
  string res;
  for (int i = 0; i < a.size(); i++) {
    c = c + a[i] - '0' + b[i] - '0';
    res += c % 10 + '0';
    c /= 10;
  }
  if (c)
    res += c + '0';
  if (res.size() > 80)
    return "overflow";
  reverse(ALL(res));
  return res;
}
int main() {
  int n;
  string a, b;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    cout << calc(a, b) << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

using namespace std;

void arrangeDigits(string str1, string str2) {
  // st1 > str2
  if (str1.length() <= str2.length()) {
    string tmp = str1;
    str1 = str2;
    str2 = tmp;
  }

  string tmp2;
  for (int i = 0; i < str1.length() - str2.length(); i++) {
    tmp2 += '0';
  }
  tmp2 += str2;
  str2 = tmp2;
  // cout << "str1: " << str1 << endl;
  // cout << "str2: " << str2 << endl;
}

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

  for (int i = 0; i < numDatasets; i++) {
    bool flag = false;
    string str1, str2;

    cin >> str1;
    // 80????¶?????????´???
    if (str1.length() > 80) {
      flag = true;
    }

    cin >> str2;
    // 80????¶?????????´???
    if (str2.length() > 80) {
      flag = true;
    }

    // ??????????????????
    arrangeDigits(str1, str2);

    //?¨????

    int c = 0;
    string res;
    for (int i = 0; i < str1.length(); i++) {
      int now;
      if ((int)((char)str2[str2.size() - i - 1] - '0') == -48) {
        now = (int)(str1[str1.size() - i - 1] - '0') + c;
      } else {
        now = (int)(str1[str1.size() - i - 1] - '0') +
              (int)((char)str2[str2.size() - i - 1] - '0') + c;
      }

      res = (char)(now % 10 + '0') + res;
      c = now / 10;
      // str1.pop_back();
      // str2.pop_back();
      // cout << "----" << endl;
      // cout << "i:" << i << endl;
      // cout << (int)(str1[str1.size()-i-1]-'0') << " + " <<
      // (int)(str2[str2.size()-i-1]-'0') << endl; cout << "now:" << now <<
      // endl; cout << "res:" << res << endl;
    }

    if (c > 0) {
      res = (char)(c - '0') + res;
    }

    if (flag == false) {

      cout << res << endl;
    } else {
      cout << "overflow" << endl;
    }
  }
}