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

#include <stdio.h>

#define N 80

// Longint <- String
int init(int a[], char s[]);
// a <- b + c
int add(int a[], int b[], int c[]);
// print Longint
void print(int a[]);

int main(void) {
  int n;
  int a[N], b[N], sum[N];
  char s[101], t[101];

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    scanf("%s", t);
    if (init(a, s) == -1 || init(b, t) == -1) {
      puts("overflow");
      continue;
    }
    if (add(sum, a, b) == -1) {
      puts("overflow");
    } else {
      print(sum);
    }
  }
  return 0;
}

// Longint <- String
int init(int a[], char s[]) {
  int len = 0;

  for (int i = 0; i < N; i++)
    a[i] = 0;
  for (char *p = s; *p != '\\0'; p++)
    len++;
  if (len > N)
    return -1;
  for (int i = 0; s[i] != '\\0'; i++) {
    a[N - len + i] = s[i] - '0';
  }
  return 0;
}
// a <- b + c
int add(int a[], int b[], int c[]) {
  int cry = 0;
  for (int i = N - 1; i >= 0; i--) {
    a[i] = b[i] + c[i] + cry;
    cry = a[i] / 10;
    a[i] %= 10;
  }
  return cry ? -1 : 0;
}

// print Longint
void print(int a[]) {
  int i;
  for (i = 0; i < N && a[i] == 0; i++)
    ;
  if (i == N) {
    puts("0");
    return;
  } else {
    for (; i < N; i++) {
      printf("%d", a[i]);
    }
    puts("");
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>
#define N 80

int main(void) {
  char buf[N * 2];
  int datas;
  int degits;
  int lint1[N + 1], lint2[N + 1], sum[N + 1];
  int cry;

  scanf("%d", &datas);
  for (int n = 0; n < datas; n++) {
    // reset
    for (int i = 0; i < N; i++)
      lint1[i] = lint2[i] = 0;
    // input
    scanf("%s", buf);
    degits = strlen(buf);
    if (degits > 80) {
      scanf("%s", buf); // read another num.
      puts("overflow");
      continue;
    }
    for (int i = 0; i < degits; i++) {
      lint1[degits - i - 1] = buf[i] - '0';
    }
    scanf("%s", buf);
    degits = strlen(buf);
    if (degits > 80) {
      puts("overflow");
      continue;
    }
    for (int i = 0; i < degits; i++) {
      lint2[degits - i - 1] = buf[i] - '0';
    }
    // calc
    cry = 0;
    for (int i = 0; i < N; i++) {
      sum[i] = lint1[i] + lint2[i] + cry;
      cry = sum[i] > 9 ? 1 : 0;
      if (cry)
        sum[i] -= 10;
    }
    // output
    if (cry) {
      puts("overflow");
    } else {
      bool zero = true;
      if (cry)
        puts("1");
      for (int i = N - 1; i >= 0; i--) {
        if (zero && sum[i] != 0)
          zero = false;
        if (!zero)
          printf("%d", sum[i], i);
      }
      printf("\\n");
    }
  }

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

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> P;
const int INF = ~(1 << 31) / 2;

int main() {
  int k;
  cin >> k;
  for (int j = 0; j < k; j++) {
    int n[80];
    string a, b;
    cin >> a >> b;
    int n_a = a.size(), n_b = b.size();
    if (n_a > 80 || n_b > 80) {
      cout << "overflow" << endl;
      continue;
    }

    fill(n, n + 80, 0);
    bool is_over = false;
    for (int i = 0; i < max(n_a, n_b); i++) {
      int ai, bi;
      if (i < n_a)
        ai = a[n_a - i - 1] - '0';
      else
        ai = 0;
      if (i < n_b)
        bi = b[n_b - i - 1] - '0';
      else
        bi = 0;
      n[i] += ai + bi;
      if (n[i] >= 10) {
        if (i + 1 == 80) {
          is_over = true;
          break;
        } else {
          n[i + 1] += n[i] / 10;
          n[i] = n[i] % 10;
        }
      }
    }
    if (is_over) {
      cout << "overflow" << endl;
    } else {
      bool started = false;
      for (int i = 79; i >= 0; i--) {
        if (!started && n[i] > 0) {
          started = true;
        }
        if (started || (!started && i == 0)) {
          cout << n[i];
        }
      }
      cout << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> P;
const int INF = ~(1 << 31) / 2;

int main() {
  int k;
  cin >> k;
  for (int j = 0; j < k; j++) {
    int n[80];
    string a, b;
    cin >> a >> b;
    int n_a = a.size(), n_b = b.size();
    fill(n, n + 80, 0);

    bool is_over = false;
    for (int i = 0; i < max(n_a, n_b); i++) {
      int ai, bi;
      if (i < n_a)
        ai = a[n_a - i - 1] - '0';
      else
        ai = 0;
      if (i < n_b)
        bi = b[n_b - i - 1] - '0';
      else
        bi = 0;
      n[i] += ai + bi;
      if (n[i] >= 10) {
        if (i + 1 == 80) {
          is_over = true;
          break;
        } else {
          n[i + 1] += n[i] / 10;
          n[i] = n[i] % 10;
        }
      }
    }
    if (is_over) {
      cout << "overflow" << endl;
    } else {
      bool started = false;
      for (int i = 79; i >= 0; i--) {
        if (!started && n[i] > 0) {
          started = true;
        }
        if (started) {
          cout << n[i];
        }
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  int N;
  string x, y, temp;
  int i, a[80];

  cin >> N;

  for (i = 0; i < 80; i++) {
    a[i] = 0;
  }

  while (N != 0) {
    bool over = false;
    if (N == 0)
      break;
    cin >> x >> y;
    N--;
    if (x.size() > 80 || y.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }

    if (x == "0" && y == "0") {
      cout << "0" << endl;
      continue;
    }

    if (x.size() < y.size()) {
      temp = x;
      x = y;
      y = temp;
    }
    int xi = 0, yi = 0;
    for (i = 0; i < x.size(); i++) {
      xi = x[x.size() - 1 - i] - '0';
      // cout << "xi = " << xi << endl;
      if (i >= y.size()) {
        yi = 0;
      } else {
        yi = y[y.size() - 1 - i] - '0';
        // cout << "yi = " << yi << endl;
      }
      a[i] += xi + yi;
      // cout << "xi + yi  = " << a[x.size() - 1 - i] << endl;
      if (a[i] > 9) {
        if (i < 79) {
          a[i] = a[i] - 10;
          a[i + 1] += 1;
        } else if (i >= 79) {
          cout << "overflow" << endl;
          over = true;
          break;
        }
      }
    }

    if (!over) {
      bool start = false;
      for (i = 79; i >= 0; i--) {
        if (!start && a[i] > 0) {
          start = true;
        }
        if (start) {
          cout << a[i];
        }
      }
      cout << endl;
    }

    for (i = 0; i < 80; i++) {
      a[i] = 0;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  int N;
  string x, y, temp;
  int i, a[80];

  cin >> N;

  for (i = 0; i < 80; i++) {
    a[i] = 0;
  }

  while (N != 0) {
    if (N == 0)
      break;
    cin >> x >> y;

    if (x.size() > 80 || y.size() > 80) {
      cout << "overflow" << endl;
    }

    if (x.size() < y.size()) {
      temp = x;
      x = y;
      y = temp;
    }
    int xi = 0, yi = 0, sum = 0;
    for (i = 0; i < x.size(); i++) {
      xi = x[x.size() - 1 - i] - '0';
      // cout << "xi = " << xi << endl;
      if (i >= y.size()) {
        yi = 0;
      } else {
        yi = y[y.size() - 1 - i] - '0';
        // cout << "yi = " << yi << endl;
      }
      a[i] += xi + yi;
      // cout << "xi + yi  = " << a[x.size() - 1 - i] << endl;
      if (a[i] > 9) {
        if (i < 79) {
          a[i] = a[i] - 10;
          a[i + 1] += 1;
        } else if (i >= 79) {
          cout << "overflow" << endl;
        }
      }
    }
    bool start = false;
    for (i = 79; i >= 0; i++) {
      if (!start && a[i] > 0) {
        start = true;
      } else if (start) {
        cout << a[i];
      }
    }
    cout << endl;
    for (i = 0; i < 80; i++) {
      a[i] = 0;
    }
    N--;
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#define MAX_NUM 32767

using namespace std;

void array_add(int *a, int *b) {
  int i;
  for (i = MAX_NUM - 1; i > 0; i--) {
    a[i] = a[i] + b[i];
    a[i - 1] = a[i - 1] + a[i] / 10;
    a[i] %= 10;
  }
}

int main(void) {
  int n, i, j, len1, len2, val1[MAX_NUM], val2[MAX_NUM];
  char c;
  scanf("%d%*c", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; (c = getchar()) != '\\n'; j++) {
      val1[j] = c - '0';
    }
    len1 = j;
    for (j = 0; (c = getchar()) != '\\n'; j++) {
      val2[j] = c - '0';
    }
    len2 = j;
    for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len1; j--) {
      val1[j] = val1[len1 - 1 + (j - (MAX_NUM - 1))];
    }
    for (; j >= 0; j--) {
      val1[j] = 0;
    }
    val1[MAX_NUM] = 0;
    for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len2; j--) {
      val2[j] = val2[len2 - 1 + (j - (MAX_NUM - 1))];
    }
    for (; j >= 0; j--) {
      val2[j] = 0;
    }
    array_add(val1, val2);
    for (j = 0; val1[j] == 0 && j < MAX_NUM; j++)
      ;
    if (j <= MAX_NUM - 81)
      printf("overflow");
    else if (j == MAX_NUM)
      printf("0");
    else {
      for (; j < MAX_NUM; j++) {
        printf("%d", val1[j]);
      }
    }
    printf("\\n");
  }
  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <cstring>
#define MAX_NUM 100

using namespace std;

void array_add(int *a, int *b) {
  int i;
  for (i = MAX_NUM - 1; i > 0; i--) {
    a[i] = a[i] + b[i];
    a[i - 1] = a[i - 1] + a[i] / 10;
    a[i] %= 10;
  }
}

int main(void) {
  int n, i, j, len1, len2, val1[MAX_NUM], val2[MAX_NUM];
  char c;
  scanf("%d%*c", &n);
  for (i = 0; i < n; i++) {
    for (j = 0; (c = getchar()) != '\\n'; j++) {
      val1[j] = c - '0';
    }
    len1 = j;
    for (j = 0; (c = getchar()) != '\\n'; j++) {
      val2[j] = c - '0';
    }
    len2 = j;
    for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len1; j--) {
      val1[j] = val1[len1 - 1 + (j - (MAX_NUM - 1))];
    }
    for (; j >= 0; j--) {
      val1[j] = 0;
    }
    val1[MAX_NUM] = 0;
    for (j = MAX_NUM - 1; j > MAX_NUM - 1 - len2; j--) {
      val2[j] = val2[len2 - 1 + (j - (MAX_NUM - 1))];
    }
    for (; j >= 0; j--) {
      val2[j] = 0;
    }
    array_add(val1, val2);
    for (j = 0; val1[j] == 0 && j < MAX_NUM; j++)
      ;
    if (j <= MAX_NUM - 81)
      printf("overflow");
    else if (j == MAX_NUM)
      printf("0");
    else {
      for (; j < MAX_NUM; j++) {
        printf("%d", val1[j]);
      }
    }
    printf("\\n");
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <utility>
using namespace std;
int toNumber(char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  }
  return 0;
}
int main() {
  int n, sa, sb, k, r, i;
  string a, b;
  int sum[100] = {};
  cin >> n;
  while (n--) {
    cin >> a >> b;
    if (a.size() < b.size())
      swap(a, b);
    sa = a.size();
    sb = b.size();
    if (sa > 80) {
      cout << "overflow\\n";
      continue;
    }
    k = i = 0;
    for (; i < sa; ++i) {
      if (i < sb)
        k = toNumber(a[sa - 1 - i]) + toNumber(b[sb - 1 - i]) + k;
      else
        k = toNumber(a[sa - 1 - i]) + k;
      r = k % 10;
      k = k / 10;
      sum[i] = r;
    }
    if (0 != k)
      sum[i] = k;
    else
      --i;
    if (i >= 80) {
      cout << "overflow\\n";
      continue;
    }
    for (int d = i; d >= 0; --d)
      cout << sum[d];
    cout << "\\n";
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>
#include <utility>
using namespace std;
int toNumber(char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  }
  return 0;
}
int main() {
  int n, sa, sb, k, r, i;
  string a, b;
  int sum[100] = {};
  cin >> n;
  while (n--) {
    cin >> a >> b;
    if (a.size() < b.size())
      swap(a, b);
    sa = a.size();
    sb = b.size();
    k = i = 0;
    for (; i < sa; ++i) {
      if (i < sb)
        k = toNumber(a[sa - 1 - i]) + toNumber(b[sb - 1 - i]) + k;
      else
        k = toNumber(a[sa - 1 - i]) + k;
      r = k % 10;
      k = k / 10;
      sum[i] = r;
    }
    if (0 != k)
      sum[i] = k;
    else
      --i;
    for (int d = i; d >= 0; --d)
      cout << sum[d];
    cout << "\\n";
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>

const int MAX_SIZE = 128;

using namespace std;

class Z {
private:
  int size;
  char d[MAX_SIZE];

public:
  Z(char *s) {
    size = strlen(s);
    for (int i = 0; i < MAX_SIZE - size; i++)
      d[i] = 0;
    for (int i = 0, j = MAX_SIZE - size; j < MAX_SIZE; i++, j++)
      d[j] = s[i];
  }

  void add(Z r) {
    int tmp = max(this->size, r.size);
    int updigit = 0;
    for (int i = MAX_SIZE - 1; i >= 0; i--) {
      int a = 0, b = 0;
      if (this->d[i] == 0 && r.d[i] == 0) {
        if (updigit) {
          this->d[i] = '1';
          tmp++;
        }
        goto end;
      } else {
        if (this->d[i])
          a = this->d[i] - '0';
        if (r.d[i])
          b = r.d[i] - '0';
        int n = a + b + updigit;
        updigit = n / 10;
        this->d[i] = (n % 10) + '0';
      }
    }
  end:
    this->size = tmp;
    return;
  }

  void print() {
    if (this->size > 80) {
      puts("overflow");
      return;
    }
    for (int i = MAX_SIZE - this->size; i < MAX_SIZE; i++)
      putchar(d[i]);
    puts("");
  }

  int sz() { return this->size; }
};

int main() {
  int x;
  scanf("%d", &x);
  char s1[1000], s2[1000];
  for (int i = 0; i < x; i++) {
    scanf("%s %s", s1, s2);
    if (strlen(s1) > 80 || strlen(s2) > 80) {
      puts("overflow");
      continue;
    }
    Z z1(s1);
    Z z2(s2);
    z1.add(z2);
    z1.print();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>

#define MAX_SIZE 90

#define toI(x) (x - '0')

using namespace std;

class Z {
private:
  int size;
  char d[MAX_SIZE];

public:
  Z(char *s) {
    size = strlen(s);
    for (int i = 0; i < MAX_SIZE - size; i++)
      d[i] = 0;
    for (int i = 0, j = MAX_SIZE - size; j < MAX_SIZE; i++, j++)
      d[j] = s[i];
  }

  void add(Z r) {
    int tmp = max(this->size, r.size);
    int updigit = 0;
    for (int i = MAX_SIZE - 1; i >= 0; i--) {
      int a = 0, b = 0;
      if (this->d[i] == 0 && r.d[i] == 0) {
        if (!updigit)
          goto end;
        this->d[i] = updigit + '0';
        updigit = 0;
        tmp++;
      } else {
        if (this->d[i])
          a = toI(this->d[i]);
        if (r.d[i])
          b = toI(r.d[i]);
        int n = a + b + updigit;
        updigit = n / 10;
        this->d[i] = (n % 10) + '0';
      }
    }
  end:
    this->size = tmp;
    return;
  }

  void print() {
    if (this->size > 80) {
      puts("overflow");
      return;
    }
    for (int i = 0; i < MAX_SIZE; i++)
      if (d[i] != -1)
        putchar(d[i]);
    puts("");
  }

  int sz() { return this->size; }
};

int main() {
  int x;
  scanf("%d", &x);
  char s1[MAX_SIZE], s2[MAX_SIZE];
  for (int i = 0; i < x; i++) {
    scanf("%s%s", s1, s2);
    /*  Z z1(s1);
       Z z2(s2);
       if(z1.sz() > 80 || z2.sz() > 80){
         puts("overflow");
         continue;
       }
       z1.add(z2);
       z1.print(); */
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    char num[2][900];
    int ans[900], up = 0, t, l;
    cin >> num[0] >> num[1];
    int a = strlen(num[0]), b = strlen(num[1]), max = (b > a) ? b : a,
        min = (b > a) ? a : b;
    for (l = 0; l < max; l++) {
      if (l < min) {
        t = (int)num[0][a - l - 1] + (int)num[1][b - l - 1] - 48 * 2 + up;
      } else if (a < b) {
        t = (int)num[1][b - l - 1] - 48 + up;
      } else {
        t = (int)num[0][a - l - 1] - 48 + up;
      }
      if (t > 9) {
        t -= 10;
        up = 1;
      } else {
        up = 0;
      }
      ans[l] = t;
    }
    if (up == 1) {
      ans[max] = 1;
      l++;
    }
    if (l <= 80)
      for (int m = l - 1; m >= 0; m--) {
        cout << ans[m];
      }
    else {
      cout << "overflow";
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    char num[2][90];
    int ans[90], up = 0, t, l;
    cin >> num[0] >> num[1];
    int a = strlen(num[0]), b = strlen(num[1]), max = (b > a) ? b : a,
        min = (b > a) ? a : b;
    for (l = 0; l < max; l++) {
      if (l < min) {
        t = (int)num[0][a - l - 1] + (int)num[1][b - l - 1] - 48 * 2 + up;
      } else if (a < b) {
        t = (int)num[1][b - l - 1] - 48 + up;
      } else {
        t = (int)num[0][a - l - 1] - 48 + up;
      }
      if (t > 9) {
        t -= 10;
        up = 1;
      } else {
        up = 0;
      }
      ans[l] = t;
    }
    if (up == 1) {
      ans[max] = 1;
      l++;
    }
    if (l <= 80)
      for (int m = l - 1; m >= 0; m--) {
        cout << ans[m];
      }
    else {
      cout << "overflow";
    }
    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;
  cin >> n;
  while (n--) {
    string a, b;
    cin >> a >> b;
    int num[900] = {0}, tab = 0, i = 0;
    int as = a.size() - 1;
    int bs = b.size() - 1;
    int nmi = min(as, bs);
    int nma = max(as, bs);
    for (int x; i <= nma; i++) {
      if (i <= nmi) {
        x = tab + a[as - i] + b[bs - i] - '0' * 2;
      } else if (as < bs) {
        x = tab + b[bs - i] - '0';
      } else if (bs < as) {
        x = tab + a[as - i] - '0';
      }
      tab = x / 10;
      num[i] = x % 10;
    }
    if (tab) {
      num[nma + 1] = tab;
      i++;
    }
    if (i > 80) {
      cout << "overflow";
    } else {
      for (int x = i - 1; x >= 0; x--) {
        cout << num[x];
      }
    }
    cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    string a, b;
    cin >> a >> b;
    int num[500] = {0}, tab = 0, i = 0;
    int as = a.size() - 1;
    int bs = b.size() - 1;
    int nmi = min(as, bs);
    int nma = max(as, bs);
    for (int x; i <= nma; i++) {
      if (i <= nmi) {
        x = tab + a[as - i] + b[bs - i] - '0' * 2;
      } else if (as < bs) {
        x = tab + b[bs - i] - '0';
      } else if (bs < as) {
        x = tab + a[as - i] - '0';
      }
      tab = x / 10;
      num[i] = x % 10;
    }
    if (tab) {
      num[nma] = tab;
      i++;
    }
    if (i > 80) {
      cout << "overflow";
    } else {
      for (int x = i - 1; x >= 0; x--) {
        cout << num[x];
      }
    }
    cout << endl;
  }
  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 a, b, ans;
    cin >> a >> b;
    int as = a.size(), bs = b.size(), ms = (as > bs) ? as : bs, t = 0;
    for (int i = 0; i < ms; i++) {
      if (i < as && i < bs) {
        t = a[as - i - 1] + b[bs - i - 1] + t / 10 - 2 * '0';
      } else if (i < as) {
        t = a[as - i - 1] + t / 10 - '0';
      } else if (i < bs) {
        t = b[bs - i - 1] + t / 10 - '0';
      }
      ans += (char)(t % 10) + '0';
    }
    if (t / 10) {
      ans += '1';
    }
    if (ans.size() > 80) {
      cout << "overflow" << endl;
    } else {
      for (int i = 0; i < ans.size(); i++) {
        cout << ans[ans.size() - i - 1];
      }
      cout << endl;
    }
  }
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int ans[200] = {0};
    string a, b;
    cin >> a >> b;
    int as = a.size(), bs = b.size(), t = 0, s = 0, x = 0;
    int ms = (as > bs) ? as : bs;
    for (int i = 0; i < ms; i++, x++) {
      if (i < as && i < bs) {
        t = a[as - i - 1] + b[bs - i - 1] - 2 * '0' + s;
      } else if (i >= as) {
        t = b[bs - i - 1] - '0' + s;
      } else if (i >= bs) {
        t = a[as - i - 1] - '0' + s;
      }
      s = t / 10;
      ans[x] = t % 10;
    }
    if (s) {
      ans[x] = s;
      x++;
    }
    if (x >= 80) {
      cout << "over flow" << endl;
    } else {
      for (int i = 0; i < x; i++) {
        cout << ans[x - i - 1];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>
int func() {
  char i1[81] = "", i2[81] = "", res[81] = "";
  bool cflag = false;
  std::string tmp;
  std::cin >> tmp;
  if (tmp.size() > 80) {
    std::cin >> tmp;
    return -1;
  }
  strcpy(i1, tmp.c_str());
  std::cin >> tmp;
  if (tmp.size() > 80)
    return -1;
  strcpy(i2, tmp.c_str());
  for (int j = 0; j < 80; j++) {
    char c = '0';
    if (cflag)
      c += 1;
    cflag = false;
    if (strlen(i1) > j) {
      c += i1[strlen(i1) - j - 1] - '0';
    }
    if (strlen(i2) > j) {
      c += i2[strlen(i2) - j - 1] - '0';
    }
    if (c > '9') {
      cflag = true;
      c -= 10;
    }
    res[79 - j] = c;
  }

  if (cflag)
    return -1;
  char *p = res;
  while (*p++ == '0' && (p - res) < 80)
    ;
  std::cout << (p - 1) << std::endl;

  return 0;
}
int main(void) {
  int n;
  std::cin >> n;
  for (int i = 0; i < n; i++)
    if (func() == -1)
      std::cout << "overflow" << std::endl;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>

int main(void) {
  int n;
  std::cin >> n;
  char i1[81] = "", i2[81] = "", res[81] = "";
  for (int i = 0; i < n; i++) {
    bool cflag = false;
    std::cin >> i1;
    if (strlen(i1) > 80) {
      std::cout << "overflow" << std::endl;
    }
    std::cin >> i2;
    if (strlen(i2) > 80) {
      std::cout << "overflow" << std::endl;
    }
    for (int j = 0; j < 80; j++) {
      char c = '0';
      if (cflag)
        c += 1;
      cflag = false;
      if (strlen(i1) > j) {
        c += i1[strlen(i1) - j - 1] - '0';
      }
      if (strlen(i2) > j) {
        c += i2[strlen(i2) - j - 1] - '0';
      }
      if (c > '9') {
        cflag = true;
        c -= 10;
      }
      res[79 - j] = c;
    }

    if (cflag) {
      std::cout << "overflow" << std::endl;
    } else {
      char *p = res;
      while (*p++ == '0')
        ;
      std::cout << (p - 1) << std::endl;
    }
  }
  return 0;
}