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

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

#define BUF_SIZE 256

int main(void) {
  char buf[BUF_SIZE];
  int num1[BUF_SIZE];
  int num2[BUF_SIZE];
  int sum[BUF_SIZE];
  char str1[BUF_SIZE];
  char str2[BUF_SIZE];
  int n;
  int i, j, k;

  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%d", &n);

  for (i = 0; i < n; i++) {
    for (j = 0; j < 100; j++) {
      num1[j] = num2[j] = sum[j] = 0;
    }

    // first integer
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%s", &str1);

    // second integer
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%s", &str2);

    // overflow
    if (strlen(str1) > 80 || strlen(str2) > 80) {
      printf("overflow\\n");
      continue;
    }

    // ??????
    for (j = 0; j < strlen(str1) - 1; j++)
      ;
    for (k = 0; j >= 0; k++) {
      num1[k] = str1[j] - '0';
      j--;
    }
    for (j = 0; j < strlen(str2) - 1; j++)
      ;
    for (k = 0; j >= 0; k++) {
      num2[k] = str2[j] - '0';
      j--;
    }

    // sum
    for (j = 0; j < 80; j++) {
      sum[j] += num1[j] + num2[j];
      if (sum[j] / 10 >= 1) {
        sum[j + 1] += sum[j] / 10;
        sum[j] = sum[j] % 10;
      }
    }

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

  return 0;
}

Error: TLE

Fixed submission:

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

#define BUF_SIZE 256

int main(void) {
  char buf[BUF_SIZE];
  int num1[100];
  int num2[100];
  int sum[100];
  char str[100];
  int n;
  int i, j, k;

  printf("error");
  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%d", &n);

  for (i = 0; i < n; i++) {
    for (j = 0; j < 100; j++) {
      num1[j] = num2[j] = sum[j] = 0;
    }

    // first integer
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%s", &str);
    if (strlen(str) > 80) {
      printf("overflow\\n");
    }

    for (j = 0; j < strlen(str) - 1; j++)
      ;
    for (k = 0; j >= 0; k++) {
      num1[k] = str[j] - '0';
      j--;
    }

    // second integer
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%s", &str);
    if (strlen(str) > 80) {
      printf("overflow\\n");
    }

    for (j = 0; j < strlen(str) - 1; j++)
      ;
    for (k = 0; j > 0; k++) {
      num2[k] = str[j] - '0';
      j--;
    }

    // sum
    for (j = 0; j < 80; j++) {
      sum[j] += num1[j] + num2[j];
      if (sum[j] / 10 >= 1) {
        sum[j + 1] += sum[j] / 10;
        sum[j] = sum[j] % 10;
      }
    }

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

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

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int max(int a, int b) { return a > b ? a : b; }
int main() {
  int n;
  cin >> n;
  for (int d = 0; d < n; d++) {
    string s, t;
    cin >> s;
    cin >> t;
    int i = 0;
    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)
      cout << "overflow" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#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[100];
    char b[100];
    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;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
using namespace std;

int N, ans[82], a, b, la, lb, up, deg;
string sta, stb;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> sta >> stb;
    la = sta.size();
    lb = stb.size();
    up = 0;
    deg = 1;
    for (int i = 0; i < max(la, lb) + 1; i++) {
      if (i >= la)
        a = '0';
      else
        a = sta[la - 1 - i];
      if (i >= lb)
        b = '0';
      else
        b = stb[lb - 1 - i];
      if (min(a, b) > 80) {
        cout << "overflow" << endl;
        continue;
      }
      if (a + b + up > 105) {
        ans[i] = a + b + up - 10 - 96;
        up = 1;
      } else {
        ans[i] = a + b + up - 96;
        up = 0;
      }
      if (ans[i] != 0)
        deg = i + 1;
    }
    if (deg > 80)
      cout << "overflow" << endl;
    else {
      for (int i = 0; i < deg; i++)
        cout << ans[deg - 1 - i];
      cout << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
using namespace std;

int N, ans[82], a, b, la, lb, up, deg;
string sta, stb;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> sta >> stb;
    la = sta.size();
    lb = stb.size();
    up = 0;
    deg = 1;
    for (int i = 0; i < max(la, lb) + 1; i++) {
      if (i >= la)
        a = '0';
      else
        a = sta[la - 1 - i];
      if (i >= lb)
        b = '0';
      else
        b = stb[lb - 1 - i];
      if (a + b + up > 105) {
        ans[i] = a + b + up - 10 - 96;
        up = 1;
      } else {
        ans[i] = a + b + up - 96;
        up = 0;
      }
      if (ans[i] != 0)
        deg = i + 1;
    }
    if (deg > 80)
      cout << "overflow" << endl;
    else {
      for (int i = 0; i < deg; i++)
        cout << ans[deg - 1 - i];
      cout << endl;
    }
  }
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define loop(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, b) loop(i, 0, b)
#define all(c) (c).begin(), (c).end()

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main() {
  int n;
  cin >> n;
  while (n--) {
    string s1, s2;
    cin >> s1 >> s2;
    int m = max(s1.size(), s2.size());
    while (m != s1.size())
      s1 = '0' + s1;
    while (m != s2.size())
      s2 = '0' + s2;
    string ans;
    int c = 0;
    for (int i = m - 1; i >= 0; i--) {
      int sum = s1[i] - '0' + s2[i] - '0' + c;
      c = sum / 10;
      sum %= 10;
      ans += sum + '0';
    }
    if (c == 1)
      ans += '1';
    reverse(all(ans));
    if (ans.size() <= 80)
      cout << ans << endl;
    else
      cout << "overflow" << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <class T> inline T sqr(T x) { return x * x; }

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \\
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

const double EPS = 1e-10;
const double PI = acos(-1.0);

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

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

  REP(i, n) {
    char s1[100], s2[100], ans[100];
    cin >> s1 >> s2;
    int len1 = strlen(s1) - 1, len2 = strlen(s2) - 1;
    if (len1 > 80 || len2 > 80) {
      cout << "overflow" << endl;
      continue;
    }

    int c = 0;
    int cnt = 0, j = len1, k = len2;
    while (j >= 0 || k >= 0 || c) {
      char s = c;
      if (j >= 0)
        s += s1[j] - '0';
      if (k >= 0)
        s += s2[k] - '0';
      if (s > 9) {
        s -= 10;
        c = 1;
      } else
        c = 0;

      s += '0';

      ans[cnt] = s;
      cnt++, j--, k--;
    }

    int len = strlen(ans);
    if (len > 80)
      cout << "overflow" << endl;
    else {
      for (j = len - 1; j >= 0; j--) {
        cout << ans[j];
      }
      cout << endl;
    }
  }
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main(int argc, char *const argv[]) {
  // insert code here...
  int n;
  string a, b;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int x[81] = {0}, y[81] = {0}, z[81] = {0};

    cin >> a;
    cin >> b;
    if (a.size() > 80 || b.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    for (int j = 0; j < a.size(); j++) {
      x[j] = a[j] - '0';
    }
    for (int j = 0; j < b.size(); j++) {
      y[j] = b[j] - '0';
    }

    for (int j = 0; j < 80; j++) {
      z[j] += x[j] + y[j];
      if (z[j] >= 10) {
        z[j + 1]++;
        z[j] -= 10;
      }
    }

    if (z[80] > 0) {
      cout << "overflow" << endl;
    } else {
      bool flag = 0;
      for (int j = 79; j >= 0; j--) {
        if (z[j] == 0 && flag == 0) {
          continue;
        } else {
          flag = 1;
        }
        cout << z[j];
      }
      if (flag == 0) {
        cout << 0;
      }
      cout << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

int main(int argc, char *const argv[]) {
  // insert code here...
  int n;
  string a, b;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int x[81] = {0}, y[81] = {0}, z[81] = {0};

    cin >> a;
    cin >> b;

    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    for (int j = 0; j < a.size(); j++) {
      x[j] = a[j] - '0';
    }
    for (int j = 0; j < b.size(); j++) {
      y[j] = b[j] - '0';
    }

    for (int j = 0; j < 80; j++) {
      z[j] += x[j] + y[j];
      if (z[j] >= 10) {
        z[j + 1]++;
        z[j] -= 10;
      }
    }

    if (z[80] > 0 || a.size() > 80 || b.size() > 80) {
      cout << "overflow" << endl;
    } else {
      bool flag = 0;
      for (int j = 79; j >= 0; j--) {
        if (z[j] == 0 && flag == 0) {
          continue;
        } else {
          flag = 1;
        }
        cout << z[j];
      }
      if (flag == 0) {
        cout << 0;
      }
      cout << endl;
    }
  }

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

#include <cctype>
#include <deque>
#include <iostream>
using namespace std;

class BigInt {
  static const int base = 10;

public:
  deque<int> digits;
  BigInt() {}
  BigInt operator+(BigInt x) {
    BigInt c;

    // add
    auto di = digits.begin(), xi = x.digits.begin(), end = digits.end();
    for (; di != end && xi != x.digits.end(); di++, xi++)
      c.digits.push_back(*di + *xi);

    // set rest
    if (di == digits.end()) {
      di = xi;
      end = x.digits.end();
    }

    for (; di != end; di++)
      c.digits.push_back(*di);

    // nomalize
    int carry = 0;
    for (int i = 0; i < c.size(); i++) {
      c.digits[i] += carry;
      carry = c.digits[i] / base;
      c.digits[i] %= base;
    }
    if (carry)
      c.digits.push_back(carry);

    return c;
  }
  int size() { return digits.size(); }
  istream &read(istream &is) {
    digits.clear();
    cin.ignore();

    int s;
    while (s = cin.get(), isdigit(s))
      digits.push_front(s - '0');
    is.putback(s);

    return is;
  }
  ostream &write(ostream &os) {
    for (auto di = digits.rbegin(); di != digits.rend(); di++)
      cout << *di;
    return os;
  }
};

istream &operator>>(istream &is, BigInt &b) { return b.read(is); }
ostream &operator<<(ostream &os, BigInt &b) { return b.write(os); }

int main() {
  for (int n; cin >> n;)
    for (BigInt a, b, c; n-- && cin >> a >> b;) {
      c = a + b;
      if (c.size() <= 80)
        cout << c << endl;
      else
        cout << "overflow" << endl;
    }

  return 0;
}

Error: -11

Fixed submission:

#include <cctype>
#include <deque>
#include <iostream>
using namespace std;

class BigInt {
  static const int base = 10;

public:
  deque<int> digits;
  BigInt() {}
  BigInt operator+(BigInt x) {
    BigInt c;

    // add
    auto di = digits.begin(), xi = x.digits.begin();
    for (; di != digits.end() && xi != x.digits.end(); di++, xi++)
      c.digits.push_back(*di + *xi);

    // set rest
    if (di == digits.end())
      di = xi;
    for (; di != digits.end(); di++)
      c.digits.push_back(*di);

    // nomalize
    int carry = 0;
    for (int i = 0; i < c.size(); i++) {
      c.digits[i] += carry;
      carry = c.digits[i] / base;
      c.digits[i] %= base;
    }
    if (carry)
      c.digits.push_back(carry);

    return c;
  }
  int size() { return digits.size(); }
  istream &read(istream &is) {
    digits.clear();
    cin.ignore();

    int s;
    while (s = cin.get(), isdigit(s))
      digits.push_front(s - '0');
    is.putback(s);

    return is;
  }
  ostream &write(ostream &os) {
    for (auto di = digits.rbegin(); di != digits.rend(); di++)
      cout << *di;
    return os;
  }
};

istream &operator>>(istream &is, BigInt &b) { return b.read(is); }
ostream &operator<<(ostream &os, BigInt &b) { return b.write(os); }

int main() {
  for (int n; cin >> n;)
    for (BigInt a, b, c; n-- && cin >> a >> b;) {
      c = a + b;
      if (c.size() < 80)
        cout << c << endl;
      else
        cout << "overflow" << endl;
    }

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

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

using std::cin;
using std::cout;
using std::endl;
using std::vector;

constexpr int MAX_DIGIT = 80;

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

  while (data_num--) {
    std::string in01_str, in02_str;
    cin >> in01_str >> in02_str;

    vector<char> in01_ch(in01_str.rbegin(), in01_str.rend());
    vector<char> in02_ch(in02_str.rbegin(), in02_str.rend());

    std::size_t size;
    if (in01_ch.size() < in02_ch.size()) {
      size = in02_ch.size();
      in01_ch.resize(size, '0');
    } else {
      size = in01_ch.size();
      in02_ch.resize(size, '0');
    }

    vector<int> in01(size), in02(size);
    for (unsigned i = 0; i < size; i++) {
      in01.at(i) = in01_ch.at(i) - '0';
      in02.at(i) = in02_ch.at(i) - '0';
    }

    vector<int> out;
    bool is_over = false;
    for (unsigned i = 0; i < size; i++) {
      int num = in01.at(i) + in02.at(i) + (is_over ? 1 : 0);
      is_over = (num > 9) ? true : false;

      out.push_back(num % 10);
    }
    if (is_over) {
      out.push_back(1);
    }

    if (out.size() > MAX_DIGIT) {
      cout << "overflow" << endl;
      continue;
    }

    for (unsigned i = 0; i < out.size(); i++) {
      cout << out.at(out.size() - 1 - i);
    }
    cout << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

constexpr int MAX_DIGIT = 80;
constexpr int OVERFLOW = 20;

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

  while (data_num--) {
    string in01_str, in02_str;
    cin >> in01_str >> in02_str;

    vector<int> in01(MAX_DIGIT + OVERFLOW, 0), in02(MAX_DIGIT + OVERFLOW, 0);
    for (unsigned i = 0; i < in01_str.size(); i++) {
      in01.at(i) = in01_str.at(in01_str.size() - 1 - i) - '0';
    }
    for (unsigned i = 0; i < in02_str.size(); i++) {
      in02.at(i) = in02_str.at(in02_str.size() - 1 - i) - '0';
    }

    if (in01.at(MAX_DIGIT) != 0 || in02.at(MAX_DIGIT) != 0) {
      cout << "overflow" << endl;
      continue;
    }

    vector<int> out(MAX_DIGIT + OVERFLOW, 0);
    for (unsigned i = 0; i < MAX_DIGIT; i++) {
      out.at(i) += in01.at(i) + in02.at(i);
      if (out.at(i) / 10 != 0) {
        out.at(i) -= 10;
        out.at(i + 1)++;
      }
    }

    if (out.at(MAX_DIGIT) != 0) {
      cout << "overflow" << endl;
      continue;
    }

    while (out.at(out.size() - 1) == 0 && out.size() != 1) {
      out.erase(out.end() - 1);
    }

    for (unsigned i = 0; i < out.size(); i++) {
      cout << out.at(out.size() - 1 - i);
    }
    cout << endl;
  }

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

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

int main() {
  int dsn;
  scanf("%d", &dsn);
  for (int dsi = 0; dsi < dsn; dsi++) {
    static char ais[10000], bis[10000];
    scanf("%s%s", ais, bis);
    int aislen = strlen(ais);
    int bislen = strlen(bis);
    if (aislen > 80 || bislen > 80) {
      printf("overflow\\n");
      continue;
    }
    static int ad[90], bd[90];
    fill(ad, ad + 90, 0);
    fill(bd, bd + 90, 0);
    for (int i = 0; i < aislen; i++)
      ad[i] = ais[aislen - 1 - i] - '0';
    for (int i = 0; i < bislen; i++)
      bd[i] = bis[bislen - 1 - i] - '0';
    int cl = 0;
    for (int i = 0; i < 90; i++) {
      ad[i] += bd[i] + cl;
      cl = ad[i] / 10;
      ad[i] %= 10;
    }
    if (ad[80]) {
      printf("overflow\\n");
      continue;
    }
    bool flag = false;
    for (int i = 89; i >= 0; i--) {
      flag = flag || ad[i];
      if (flag) {
        printf("%d", ad[i]);
      }
    }
    if (!flag)
      printf("0");
    printf("\\n");
  }
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int dsn;
  scanf("%d", &dsn);
  for (int dsi = 0; dsi < dsn; dsi++) {
    static char ais[90], bis[90];
    scanf(" %s %s", ais, bis);
    int aislen = strlen(ais);
    int bislen = strlen(bis);
    static int ad[90], bd[90];
    fill(ad, ad + 90, 0);
    fill(bd, bd + 90, 0);
    for (int i = 0; i < aislen; i++)
      ad[i] = ais[aislen - 1 - i] - '0';
    for (int i = 0; i < bislen; i++)
      bd[i] = bis[bislen - 1 - i] - '0';
    int cl = 0;
    for (int i = 0; i < 90; i++) {
      ad[i] += bd[i] + cl;
      cl = ad[i] / 10;
      ad[i] %= 10;
    }
    bool flag = false;
    for (int i = 89; i >= 0; i--) {
      flag = flag || ad[i];
      if (flag) {
        printf("%d", ad[i]);
      }
    }
    if (!flag)
      printf("0");
    printf("\\n");
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  string s1, s2, ans;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s1;
    cin >> s2;
    ans = "";
    int m = max(s1.size(), s2.size());
    while (m > s1.size())
      s1 = '0' + s1;
    while (m > s2.size())
      s2 = '0' + s2;

    int carry = 0;
    for (int j = m - 1; j >= 0; j--) {
      char ch = ((s1[j] - '0') + (s2[j] - '0') + carry) % 10 + '0';
      carry = ((s1[j] - '0') + (s2[j] - '0') + carry) / 10;
      ans += ch; // 反転してしまうが…
    }
    if (carry)
      ans += (carry + '0');
    reverse(ans.begin(), ans.end()); // 元通り

    // 頭の0を削除していく
    while (ans.size() > 1 && ans[0] == '0')
      ans.erase(ans.begin());
    if (ans.size() > 80)
      cout << "overflow" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n;
  string s1, s2, ans;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> s1;
    cin >> s2;
    ans = "";
    reverse(s1.begin(), s1.end());
    reverse(s1.begin(), s2.end()); // 反転
    int m = max(s1.size(), s2.size());
    while (m > s1.size())
      s1 += '0';
    while (m > s2.size())
      s2 += '0';

    int carry = 0;
    for (int j = 0; j < m; j++) {
      char ch = ((s1[j] - '0') + (s2[j] - '0') + carry) % 10 + '0';
      carry = ((s1[j] - '0') + (s2[j] - '0') + carry) / 10;
      ans += ch;
    }
    if (carry)
      ans += (carry + '0');
    reverse(ans.begin(), ans.end()); // 元通り

    // 頭の0を削除していく
    while (ans.size() > 1 && ans[0] == '0')
      ans.erase(ans.begin());
    if (ans.size() > 80)
      cout << "overflow" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}