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

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
char ans[101];
char n1[101];
char n2[101];
int main() {
  int d;
  int h1, h2, limit;
  for (cin >> d; d > 0; d--) {
    for (int j = 0; j < 100; j++)
      ans[j] = '0';
    scanf("%s", n1);
    scanf("%s", n2);
    h1 = strlen(n1) - 1;
    h2 = strlen(n2) - 1;
    limit = max(h1, h2);
    int i;
    bool flg = false;
    for (i = 0; i <= limit; i++, h1--, h2--) {
      flg = false;
      int n1_tmp = 0;
      int n2_tmp = 0;
      if (h1 >= 0) {
        n1_tmp = n1[h1] - '0';
      }
      if (h2 >= 0) {
        n2_tmp = n2[h2] - '0';
      }
      int sum = n1_tmp + n2_tmp;
      if (sum >= 10) {
        if (i == 79) {
          i++;
          flg = true;
          break;
        }
        ans[i + 1] += 1;
        sum = sum % 10;
        flg = true;
      }

      if (ans[i] - '0' + sum > 9) {
        if (i == 79) {
          i++;
          flg = true;
          break;
        }
        ans[i] = ans[i] + (sum - 10);
        ans[i + 1] += 1;
        flg = true;
      } else
        ans[i] += sum;
    }
    if (flg) {
      i++;
    }
    ans[i] = '\\0';
    if (i > 80)
      cout << "overflow" << endl;
    else {
      for (--i; i >= 0; i--) {
        if (i >= 0)
          cout << ans[i];
      }
      cout << endl;
    }
    //		cout<<"size:"<<strlen(ans)<<endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int d;
  for (cin >> d; d > 0; d--) {
    char ans[200];
    char n1[200];
    char n2[200];
    for (int i = 0; i < 200; i++)
      ans[i] = '0';
    scanf("%s", n1);
    scanf("%s", n2);
    int h1 = strlen(n1) - 1;
    int h2 = strlen(n2) - 1;
    int limit = max(h1, h2);
    int i;
    bool flg = false;
    for (i = 0; i <= limit; i++, h1--, h2--) {
      flg = false;
      int n1_tmp = 0;
      int n2_tmp = 0;
      if (h1 >= 0) {
        n1_tmp = n1[h1] - '0';
      }
      if (h2 >= 0) {
        n2_tmp = n2[h2] - '0';
      }
      int sum = n1_tmp + n2_tmp;
      if (sum >= 10) {
        if (i == 79) {
          i++;
          flg = true;
          break;
        }
        ans[i + 1] = ans[i + 1] + 1;
        sum = sum % 10;
        flg = true;
      }

      if (ans[i] + sum > '9') {
        if (i == 79) {
          i++;
          flg = true;
          break;
        }
        ans[i] = ans[i] + (sum - 10);
        ans[i + 1] += 1;
        flg = true;
      } else
        ans[i] += sum;
    }
    if (flg) {
      i++;
    }
    ans[i] = '\\0';
    if (i >= 80)
      cout << "overflow" << endl;
    else {
      for (--i; i >= 0; i--) {
        if (i >= 0)
          cout << ans[i];
      }
      cout << endl;
    }
    //		cout<<"size:"<<strlen(ans)<<endl;
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  cin >> n;
  while (n-- > 0) {
    string num1, num2;
    cin >> num1 >> num2;
    if (num1.size() > 80 || num2.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    int sum[101];
    int degit = 0;
    for (int i = 0; i < 101; i++)
      sum[i] = 0;
    for (int i = 0; i < num1.size(); i++) {
      sum[100 - i] = num1[num1.size() - i - 1] - '0';
    }
    int d;
    for (int i = 0; i < num1.size() || i < num2.size() || degit != 0; i++) {
      int now;
      if (i < num2.size()) {
        now =
            sum[100 - i] + (int)num2[num2.size() - i - 1] - (int)('0') + degit;
      } else {
        now = sum[100 - i] + degit;
      }
      sum[100 - i] = (now % 10);
      if (now >= 10)
        degit = 1;
      else
        degit = 0;
      d = i;
    }
    if (d < 80) {
      for (int i = 100 - d; i < 101; i++)
        cout << sum[i];
      cout << endl;
    } else {
      cout << "overflow" << endl;
    }
  }
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  while (n-- > 0) {
    string num1, num2;
    cin >> num1 >> num2;
    int sum[101];
    int degit = 0;
    for (int i = 0; i < 101; i++)
      sum[i] = 0;
    for (int i = 0; i < num1.size(); i++) {
      sum[100 - i] = num1[num1.size() - i - 1] - '0';
    }
    int d;
    for (int i = 0; i < num1.size() || i < num2.size() || degit != 0; i++) {
      int now;
      if (i < num2.size()) {
        now =
            sum[100 - i] + (int)num2[num2.size() - i - 1] - (int)('0') + degit;
      } else {
        now = sum[100 - i] + degit;
      }
      sum[100 - i] = (now % 10);
      if (now >= 10)
        degit = 1;
      else
        degit = 0;
      d = i;
    }
    if (d < 80) {
      for (int i = 100 - d; i < 101; i++)
        cout << sum[i];
      cout << endl;
    } else {
      cout << "overflow" << endl;
    }
  }
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, l1, l2, i;
  string a, b;
  char ans[80];
  int ia, ib, sum;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    if (a.length() > 80 || b.length() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    if (a.length() == 80 || b.length() == 80) {
      if ((int)a[0] - '0' + (int)b[0] - '0' > 9) {
        cout << "overflow" << endl;
        continue;
      }
    }
    if (a.length() < b.length()) {
      swap(a, b);
    }
    l1 = a.length();
    l2 = b.length();
    for (i = 0; i < 80; i++)
      ans[i] = 0;
    for (i = 1; i < l2 + 1; i++) {
      ia = (int)a[l1 - i] - (int)'0';
      ib = (int)b[l2 - i] - (int)'0';
      sum = ia + ib;
      ans[80 - i] += sum + '0';
    }
    for (i = l2 + 1; i < l1 + 1; i++) {
      ans[80 - i] = a[l1 - i];
    }
    for (i = 79; i >= 0; i--) {
      if (ans[i] - '0' > 9 && ans[i] != 0) {
        ans[i] = ans[i] - 10;
        if (ans[i - 1] == 0)
          ans[i - 1] += 49;
        else
          ans[i - 1] += 1;
      }
    }
    for (i = 0; i < 80; i++) {
      if (ans[i] != 0) {
        cout << (int)ans[i] - '0';
      }
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  int n, l1, l2, i;
  string a, b;
  char ans[80];
  int ia, ib, sum;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    if (a.length() > 80 || b.length() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    if (a.length() == 80 || b.length() == 80) {
      if ((int)a[0] - '0' + (int)b[0] - '0' > 9) {
        cout << "overflow" << endl;
        continue;
      }
    }
    if (a.length() < b.length()) {
      swap(a, b);
    }
    l1 = a.length();
    l2 = b.length();
    for (i = 0; i < 80; i++)
      ans[i] = 0;
    for (i = 1; i < l2 + 1; i++) {
      ia = (int)a[l1 - i] - (int)'0';
      ib = (int)b[l2 - i] - (int)'0';
      sum = ia + ib;
      ans[80 - i] += sum + '0';
    }
    for (i = l2 + 1; i < l1 + 1; i++) {
      ans[80 - i] = a[l1 - i];
    }
    for (i = 79; i >= 0; i--) {
      if (ans[i] - '0' > 9 && ans[i] != 0) {
        ans[i] = ans[i] - 10;
        if (ans[i - 1] == 0)
          ans[i - 1] += 49;
        else
          ans[i - 1] += 1;
      }
    }
    for (i = 0; i < 80; i++) {
      if (ans[i] != 0) {
        cout << (int)ans[i] - '0';
      }
    }
    cout << endl;
  }
  while (1)
    ;
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <string.h>
// #include<string>

using namespace std;

#define MAX(x, y) ((x > y) ? x : y)

int n; // データセットの数

char str[2][10000]; //	入力される整数文字列
int n_str[2];       // 長さを収納

char answer[85];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {

    scanf("%s%s", &str[0], &str[1]);
    n_str[0] = strlen(str[0]);
    n_str[1] = strlen(str[1]);
    int max = 0, min = 1;
    if (n_str[1] > n_str[0]) {
      max = 1;
      min = 0;
    }
    int s = n_str[max] - n_str[min];
    char cha[10000];
    fill(cha, cha + 80, '0');
    for (int j = n_str[min]; j >= 0; j--) {
      cha[j + s] = str[min][j];
    }
    strcpy(str[min], cha);
    fill(answer, answer + 85, 0);
    for (int j = n_str[max] - 1; j >= 0; j--) {
      answer[j] = str[0][j] + str[1][j] - '0';
      if (answer[j] > '9') // 繰り上がり時の処理
      {
        answer[j] -= 10;
        if (j == 0) {
          if (n_str[max] >= 80) {
            n_str[max] = 90;
          }

          else
            printf("1");
        } else
          str[0][j - 1]++;
      }
    }
    if (n_str[max] > 80) {
      printf("overflow\\n");
    } else
      printf("%s\\n", answer);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <string.h>
// #include<string>

using namespace std;

#define MAX(x, y) ((x > y) ? x : y)

int n; // データセットの数

char str[2][10000]; //	入力される整数文字列
int n_str[2];       // 長さを収納

char answer[85];

FILE *fp = stdin;

int main() {
  fscanf(fp, "%d", &n);
  for (int i = 0; i < n; i++) {
  sta:
    fscanf(fp, "%s%s", &str[0], &str[1]);
    for (int j = 0; j < 2; j++)
      n_str[j] = strlen(str[j]);
    int max = 0, min = 1;
    if (n_str[1] > n_str[0]) {
      max = 1;
      min = 0;
    }
    int s = n_str[max] - n_str[min];
    char cha[10000];
    fill(cha, cha + 80, '0');
    for (int j = n_str[min]; j >= 0; j--) {
      cha[j + s] = str[min][j];
    }
    strcpy(str[min], cha);
    fill(answer, answer + 85, 0);
    for (int j = n_str[max] - 1; j >= 0; j--) {
      answer[j] = str[0][j] + str[1][j] - '0';
      if (answer[j] > '9') // 繰り上がり時の処理
      {
        answer[j] -= 10;
        if (j == 0) {
          if (n_str[max] >= 80) {
            n_str[max]++;
          }

          else
            printf("1");
        } else
          str[0][j - 1]++;
      }
    }
    if (n_str[max] > 80) {
      printf("overflow\\n");
    } else
      printf("%s\\n", answer);
  }
  fclose(fp);
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main(void) {
  int y;
  scanf("%d", &y);
  for (int z = 0; z < y; z++) {
    char suji1[100000], suji2[100000];
    char ans[100000] = {0};

    for (int i = 0; i < 82; i++) {
      suji1[i] = '0';
      suji2[i] = '0';
    }

    int overflow = 0;

    scanf("%s", suji1);
    scanf("%s", suji2);
    int suji1s = strlen(suji1);
    int suji2s = strlen(suji2);

    int anss;
    if (suji1s > suji2s)
      anss = suji1s;
    else
      anss = suji2s;

    suji1[suji1s] = '0';
    suji2[suji2s] = '0';

    reverse(suji1, suji1 + suji1s);
    reverse(suji2, suji2 + suji2s);

    for (int i = 0; i < 81; i++) {
      ans[i] = suji1[i] + suji2[i] - '0';
      if (ans[i] >= ':') {
        ans[i] = ans[i] - 10;
        suji2[i + 1] = suji2[i + 1] + 1;
      }
    }
    if (ans[anss] > '0') {
      anss++;
    }

    if (anss > 80)
      overflow = 1;
    reverse(ans, ans + anss);
    ans[anss] = 0;
    if (overflow >= 1) {
      printf("overflow");
    } else {
      printf("%s", ans);
    }
    printf("\\n");
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main(void) {
  int y;
  scanf("%d", &y);
  for (int z = 0; z < y; z++) {
    char suji1[82], suji2[82];
    char ans[82] = {0};

    for (int i = 0; i < 82; i++) {
      suji1[i] = '0';
      suji2[i] = '0';
    }

    int overflow = 0;

    scanf("%s", suji1);
    scanf("%s", suji2);
    int suji1s = strlen(suji1);
    int suji2s = strlen(suji2);

    int anss;
    if (suji1s > suji2s)
      anss = suji1s;
    else
      anss = suji2s;

    suji1[suji1s] = '0';
    suji2[suji2s] = '0';

    reverse(suji1, suji1 + suji1s);
    reverse(suji2, suji2 + suji2s);

    for (int i = 0; i < 80; i++) {
      ans[i] = suji1[i] + suji2[i] - '0';
      if (ans[i] >= ':') {
        ans[i] = ans[i] - 10;
        suji2[i + 1] = suji2[i + 1] + 1;
      }
    }

    if (ans[anss] != '0')
      anss++;
    if (anss >= 81)
      overflow = 1;
    reverse(ans, ans + anss);
    ans[anss] = 0;
    if (overflow >= 1) {
      printf("overflow\\n");
    } else {
      printf("%s\\n", ans);
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;

int main() {
  int x[100];
  int y[100];
  int z[100];
  int n, i, j, hi;
  bool top;
  string a, b;

  cin >> n;
  for (i = 0; i < n; i++) {
    // initialize
    for (j = 0; j < 100; j++) {
      x[j] = 0;
      y[j] = 0;
      z[j] = 0;
    }
    cin >> a;
    cin >> b;
    if (a.length() > 80 || b.length() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    for (j = 0; j < a.length(); j++) {
      x[j] = atoi(a.substr(a.length() - 1 - j, 1).c_str());
    }
    for (j = 0; j < b.length(); j++) {
      y[j] = atoi(b.substr(b.length() - 1 - j, 1).c_str());
    }

    hi = 0;
    for (j = 0; j < 80; j++) {
      z[j] = x[j] + y[j] + hi;
      if (z[j] > 9) {
        hi = 1;
        z[j] -= 10;
      } else {
        hi = 0;
      }
    }
    if (hi == 1) {
      cout << "overflow" << endl;
    } else {
      top = false;
      for (j = 79; j > -1; j--) {
        if (z[j] == 0 && !top && j != 0) {
          continue;
        } else {
          top = true;
          cout << z[j];
        }
      }
      cout << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;

int main() {
  int x[100];
  int y[100];
  int z[100];
  int n, i, j, hi;
  bool top;
  string a, b;

  cin >> n;
  for (i = 0; i < n; i++) {
    // initialize
    for (j = 0; j < 100; j++) {
      x[j] = 0;
      y[j] = 0;
      z[j] = 0;
    }
    cin >> a;
    cin >> b;
    for (j = 0; j < a.length(); j++) {
      x[j] = atoi(a.substr(a.length() - 1 - j, 1).c_str());
    }
    for (j = 0; j < b.length(); j++) {
      y[j] = atoi(b.substr(b.length() - 1 - j, 1).c_str());
    }

    hi = 0;
    for (j = 0; j < 80; j++) {
      z[j] = x[j] + y[j] + hi;
      if (z[j] > 9) {
        hi = 1;
        z[j] -= 10;
      } else {
        hi = 0;
      }
    }
    if (hi == 1) {
      cout << "overflow" << endl;
    } else {
      top = false;
      for (j = 79; j > -1; j--) {
        if (z[j] == 0 && !top) {
          continue;
        } else {
          top = true;
          cout << z[j];
        }
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void) {
  char a[200], b[200], result[200], temp[200];
  int ketaagari;
  int i, j;
  int max;
  char in;
  int overflow;
  int count, kazu;
  scanf("%d", &kazu);
  for (count = 0; count < kazu; count++) {
    for (i = 0; i < 200; i++) {
      a[i] = 0;
      b[i] = 0;
    }
    i = 0;
    overflow = 0;

    scanf(" %s ", temp);
    i = strlen(temp);
    if (i > 80)
      overflow = 1;
    else
      for (j = 0; j < i; j++)
        a[j] = temp[i - j - 1] - '0';

    scanf(" %s ", temp);
    i = strlen(temp);
    if (i > 80)
      overflow = 1;
    else
      for (j = 0; j < i; j++)
        b[j] = temp[i - j - 1] - '0';

    for (i = 0, ketaagari = 0, max = 0; i < 80; i++) {
      result[i] = (a[i] + b[i] + ketaagari) % 10;
      ketaagari = (a[i] + b[i] + ketaagari) / 10;
      if (result[i] != 0)
        max = i;
    }
    if (ketaagari)
      overflow = 1;

    if (overflow == 0) {
      for (i = max; i >= 0; i--)
        printf("%d", result[i]);
      printf("\\n");
    } else
      printf("overflow\\n");
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  char a[200], b[200], result[200], temp[200];
  int ketaagari;
  int i, j;
  int max;
  char in;
  int overflow;
  int count, kazu;
  scanf("%d", &kazu);
  for (count = 0; count < kazu; count++) {
    for (i = 0; i < 200; i++) {
      a[i] = 0;
      b[i] = 0;
    }
    i = 0;
    overflow = 0;

    scanf(" %s ", temp);

    i = strlen(temp);
    if (i > 80)
      overflow = 1;
    for (j = 0; j < i; j++)
      a[j] = temp[i - j - 1] - '0';
    scanf(" %s ", temp);
    i = strlen(temp);
    if (i > 80)
      overflow = 1;

    for (j = 0; j < i; j++)
      b[j] = temp[i - j - 1] - '0';

    for (i = 0, ketaagari = 0, max = 0; i < 80; i++) {
      result[i] = (a[i] + b[i] + ketaagari) % 10;
      ketaagari = (a[i] + b[i] + ketaagari) / 10;
      if (result[i] != 0)
        max = i;
    }
    if (ketaagari)
      overflow = 1;

    if (overflow == 0) {
      for (i = max; i >= 0; i--)
        printf("%d", result[i]);
      printf("\\n");
    } else
      printf("overflow\\n");
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string.h>
#define rep(i, n) for (i = 0; i < n; i++)
#define MAX(a, b) (a > b ? a : b)
using namespace std;

int N;
char stra[100000], strb[100000], *ans[10000];
int sum[10000][81];

int main() {
  int i, j;
  int a[80], b[80];
  cin >> N;
  rep(i, N) {
    int la, lb;
    cin >> stra;
    cin >> strb;
    la = strlen(stra);
    lb = strlen(strb);
    if (la > 80 || lb > 80) {
      ans[i] = "overflow";
      continue;
    }
    rep(j, 80) {
      a[j] = 0;
      b[j] = 0;
    }
    // 小さい桁をインデックスの小さいほうに入れたい。
    for (j = la - 1; j >= 0; j--)
      a[j] = stra[la - 1 - j] - 48;
    for (j = lb - 1; j >= 0; j--)
      b[j] = strb[lb - 1 - j] - 48;
    // 小さい桁から計算
    rep(j, MAX(la, lb)) {
      sum[i][j] += a[j] + b[j];
      sum[i][j + 1] += (sum[i][j]) / 10;
      sum[i][j] %= 10;
    }
    if (sum[i][80] > 0) {
      ans[i] = "overflow";
      continue;
    }
    ans[i] = "j";
  }
  rep(i, N) {
    if (*ans[i] == 'o') {
      cout << ans[i] << endl;
      continue;
    }
    for (j = 79; sum[i][j] == 0 && j > 0; j--)
      ;
    for (; j >= 0; j--)
      cout << sum[i][j];
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string.h>
#define MAX(x, y) (x > y ? x : y)
using namespace std;

int N;
int sum[1000][100];
char stra[1000][85], strb[1000][85];

int main() {
  int i, j;
  int a[100], b[100];
  cin >> N;
  for (i = 0; i < N; i++) {
    for (j = 0; j < 100; j++) {
      a[j] = 0;
      b[j] = 0;
    }
    cin >> stra[i];
    for (j = strlen(stra[i]) - 1; j >= 0; j--) {
      a[j] = stra[i][strlen(stra[i]) - 1 - j] - 48;
    }
    cin >> strb[i];
    for (j = strlen(strb[i]) - 1; j >= 0; j--) {
      b[j] = strb[i][strlen(strb[i]) - 1 - j] - 48;
    }
    for (j = 0; j < MAX(strlen(stra[i]), strlen(strb[i])); j++) {
      sum[i][j] += (a[j] + b[j]);
      sum[i][j + 1] += (sum[i][j]) / 10;
      sum[i][j] %= 10;
    }
  }
  for (i = 0; i < N; i++) {
    for (j = 99; sum[i][j] == 0 && j > 0; j--)
      ;
    if (j >= 80)
      cout << "overflow" << endl;
    else {
      for (j; j >= 0; j--)
        cout << sum[i][j];
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  string L, R;
  int left, right, i, j, N;
  cin >> N;
  while (N--) {
    cin >> L >> R;
    left = L.length(), right = R.length();
    if (left >= right) {
      if (left > 80) {
        cout << "overflow" << endl;
        continue;
      }
      R.resize(left);
      for (i = right - 1, j = left - 1; i >= 0; i--, j--)
        R[j] = R[i];
      right = left;
      for (; j >= 0; R[j--] = '0')
        ;
    } else {
      if (right > 80) {
        cout << "overflow" << endl;
        continue;
      }
      L.resize(right);
      for (i = right - 1, j = left - 1; j >= 0; i--, j--)
        L[i] = L[j];
      left = right;
      for (; i >= 0; L[i--] = '0')
        ;
    }
    L[left] = 0;
    for (i = left - 1, j = 0; i >= 0; i--) {
      L[i] += R[i] + j - 48;
      if (L[i] > '9')
        j = 1, L[i] -= 10;
      else
        j = 0;
    }
    i = L.length() + j;
    if (i > 80)
      cout << "overflow" << endl;
    else {
      if (j)
        cout << "1";
      cout << L << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
#include <string.h>
int main() {
  char L[85], R[85];
  int left, right, i, j, N;
  scanf("%d", &N);
  while (N--) {
    scanf("%s\\n%s", &L, &R);
    left = strlen(L), right = strlen(R);
    if (left >= right) {
      for (i = right - 1, j = left - 1; i >= 0; i--, j--)
        R[j] = R[i];
      right = left;
      for (; j >= 0; R[j--] = '0')
        ;
    } else {
      for (i = right - 1, j = left - 1; j >= 0; i--, j--)
        L[i] = L[j];
      left = right;
      for (; i >= 0; L[i--] = '0')
        ;
    }
    L[left] = 0;
    for (i = left - 1, j = 0; i >= 0; i--) {
      L[i] += R[i] + j - 48;
      if (L[i] > '9')
        j = 1, L[i] -= 10;
      else
        j = 0;
    }
    if (j)
      printf("1");
    puts(L);
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)

int main() {
  string a, b;
  vector<int> m, n, s;
  int set;

  m.resize(81, 0);
  n.resize(81, 0);
  s.resize(81, 0);

  cin >> set;
  while (set-- > 0) {
    cin >> a >> b;
    for (int i = 0; i < 81; i++) {
      m[i] = n[i] = s[i] = 0;
    }
    if (a.size() > 80 || b.size() > 80) {
      cout << "overflow" << endl;
    } else {
      reverse(a.begin(), a.end());
      reverse(b.begin(), b.end());
      for (int i = 0; i < a.size(); i++) {
        m[i] = a[i] - '0';
      }
      for (int i = 0; i < b.size(); i++) {
        n[i] = b[i] - '0';
      }
      for (int i = 0; i < 80; i++) {
        s[i] += m[i] + n[i];
        if (s[i] >= 10) {
          s[i + 1]++;
          s[i] -= 10;
        }
      }
      int digit = 81;
      while (--digit > 0) {
        if (s[digit] != 0) {
          break;
        }
      }
      if (digit >= 80) {
        cout << "overflow" << endl;
      } else {
        for (int i = digit; i >= 0; i--) {
          cout << s[i];
        }
        cout << endl;
      }
    }
  }

  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)

int main() {
  string a, b;
  vector<int> m, n, s;
  int set;

  m.resize(81, 0);
  n.resize(81, 0);
  s.resize(81, 0);

  cin >> set;
  while (set-- > 0) {
    a.clear();
    b.clear();
    cin >> a >> b;
    for (int i = 0; i < 81; i++) {
      m[i] = n[i] = s[i] = 0;
    }
    if (a.size() > 80 || a.size() > 80) {
      cout << "overflow" << endl;
    } else {
      reverse(a.begin(), a.end());
      reverse(b.begin(), b.end());
      for (int i = 0; i < a.size(); i++) {
        m[i] = a[i] - '0';
      }
      for (int i = 0; i < b.size(); i++) {
        n[i] = b[i] - '0';
      }
      for (int i = 0; i < 80; i++) {
        s[i] += m[i] + n[i];
        if (s[i] >= 10) {
          s[i + 1]++;
          s[i] -= 10;
        }
      }
      int digit = 81;
      while (--digit > 0) {
        if (s[digit] != 0)
          break;
      }
      if (digit >= 79) {
        cout << "overflow" << endl;
      } else {
        for (int i = digit; i >= 0; i--) {
          cout << s[i];
        }
        cout << endl;
      }
    }
  }

  return 0;
}