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

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int w;
  while (scanf("%d", &w) != EOF) {

    int i;
    long long area = 0;
    for (i = w; i < 600; i += w) {
      area += w * i * i;
    }
    printf("%lld\\n", area);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int w;
  while (scanf("%d", &w) && w) {

    int i;
    long long area = 0;
    for (i = w; i < 600; i += w) {
      area += w * i * i;
    }
    printf("%lld\\n", area);
  }
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

// RE
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < j; i++)
#define FOR(i, j, k) for (int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int N = 100;

vector<int> makeDx(string str) {
  reverse(str.begin(), str.end());
  vector<int> ret(N, 0);
  REP(i, str.size()) ret[i] = str[i] - '0';
  return ret;
}

bool isOver80(vector<int> dx) {
  FOR(i, 80, dx.size()) if (dx[i] != 0) return true;
  return false;
}

int main() {
  int n;
  cin >> n;
  REP(z, n) {
    string str[2];
    cin >> str[0] >> str[1];
    if (str[0].size() > 80 || str[1].size() > 80) {
      cout << "overflow" << endl;
      continue;
    }

    vector<int> dx[2] = {makeDx(str[0]), makeDx(str[1])};
    vector<int> ans(N, 0);

    REP(i, max(dx[0].size(), dx[1].size())) {
      ans[i] += (dx[0][i] + dx[1][i]);
      ans[i + 1] += (ans[i] / 10);
      ans[i] %= 10;
    }

    if (isOver80(ans)) {
      cout << "overflow" << endl;
      continue;
    }

    reverse(ans.begin(), ans.end());
    int s = 0;
    while (ans[s] == 0 && s < ans.size() - 1)
      s++;
    // debug
    // cout <<"size = " <<ans.size() - s <<endl;
    FOR(i, s, ans.size()) cout << ans[i];
    cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

// RE
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < j; i++)
#define FOR(i, j, k) for (int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;
const int N = 100;

vector<int> makeDx(string str) {
  reverse(str.begin(), str.end());
  vector<int> ret(N, 0);
  REP(i, str.size()) ret[i] = str[i] - '0';
  return ret;
}

bool isOver80(vector<int> dx) {
  FOR(i, 80, dx.size()) if (dx[i] != 0) return true;
  return false;
}

int main() {
  int n;
  cin >> n;
  REP(z, n) {
    string str[2];
    cin >> str[0] >> str[1];
    if (str[0].size() > 80 || str[0].size() > 80) {
      cout << "NA" << endl;
      continue;
    }

    vector<int> dx[2] = {makeDx(str[0]), makeDx(str[1])};
    vector<int> ans(N, 0);

    REP(i, max(dx[0].size(), dx[1].size())) {
      ans[i] += (dx[0][i] + dx[1][i]);
      ans[i + 1] += (ans[i] / 10);
      ans[i] = ans[i] % 10;
    }

    if (isOver80(ans)) {
      cout << "NA" << endl;
      continue;
    }

    reverse(ans.begin(), ans.end());
    int s = 0;
    while (ans[s] == 0 && s < N - 1)
      s++;
    FOR(i, s, N) cout << ans[i];
    cout << endl;
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    char s[1024], t[1024];
    scanf("%s%s", s, t);
    int m = strlen(s), n = strlen(t);

    int a[1024] = {}, b[1024] = {};
    rep(i, m) a[i] = s[m - i - 1] - '0';
    rep(i, n) b[i] = t[n - i - 1] - '0';

    m = max(m, n);
    int c[1024] = {};
    rep(i, m) {
      int tmp = a[i] + b[i] + c[i];
      c[i] = tmp % 10;
      c[i + 1] += tmp / 10;
    }
    if (c[m] != 0)
      m++;

    if (m > 80)
      puts("overflow");
    else {
      rep(i, m) putchar(c[m - i - 1] + '0');
      puts("");
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    char s[128], t[128];
    scanf("%s%s", s, t);
    int m = strlen(s), n = strlen(t);

    int a[128] = {}, b[128] = {};
    rep(i, m) a[i] = s[m - i - 1] - '0';
    rep(i, n) b[i] = t[n - i - 1] - '0';

    m = max(m, n);
    int c[128] = {};
    rep(i, m) {
      int tmp = a[i] + b[i] + c[i];
      c[i] = tmp % 10;
      c[i + 1] += tmp / 10;
    }
    if (c[m] != 0)
      m++;

    if (m > 80)
      puts("overflow");
    else {
      rep(i, m) putchar(c[m - i - 1] + '0');
      puts("");
    }
  }

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

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

int main(void) {
  int N, j, k = 0;
  cin >> N;
  char strA[100000], strB[100000];
  while (1) {
    k++;
    if (k == N + 1) {
      break;
    }
    cin >> strA >> strB;
    int ans[81] = {0};
    ans[0] = 11111;
    if (strlen(strA) > 80 || strlen(strB) > 80) {
      cout << "overflow" << endl;
      continue;
    }
    int a[81] = {0}, b[81] = {0};
    if (strA[strlen(strA) - 1] == '0' && strB[strlen(strB) - 1] == '0') {
      cout << 0 << endl;
      continue;
    }
    j = strlen(strA) - 1;
    for (int i = 80; j >= 0; i--) {
      a[i] = (int)strA[j] - 48;
      j--;
    }
    j = strlen(strB) - 1;
    for (int i = 80; j >= 0; i--) {
      b[i] = (int)strB[j] - 48;
      j--;
    }
    for (int i = 80; i != 0; i--) {
      ans[i] = ans[i] + a[i] + b[i];
      if (ans[i] >= 10) {
        ans[i] = ans[i] - 10;
        ans[i - 1]++;
      }
    }
    if (ans[0] != 11111) {
      cout << "overflow" << endl;
      continue;
    }
    for (int i = 1; i < 81; i++) {
      if (ans[i] != 0) {
        j = i;
        break;
      }
    }
    char c[3];
    for (int i = j; i < 81; i++) {
      printf("%c", ans[i] + 48);
    }
    cout << '\\n';
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int N, j, k = 0;
  cin >> N;
  char strA[300], strB[300];
  while (1) {
    k++;
    if (k == N + 1) {
      break;
    }
    cin >> strA >> strB;
    int ans[81] = {0};
    ans[0] = 11111;
    if (strlen(strA) > 80 || strlen(strB) > 80) {
      cout << "overflow" << endl;
      continue;
    }
    int a[81] = {0}, b[81] = {0};
    if (strA[strlen(strA) - 1] == '0' && strB[strlen(strB) - 1] == '0') {
      cout << 0 << endl;
      continue;
    }
    j = strlen(strA) - 1;
    for (int i = 80; j >= 0; i--) {
      a[i] = (int)strA[j] - 48;
      j--;
    }
    j = strlen(strB) - 1;
    for (int i = 80; j >= 0; i--) {
      b[i] = (int)strB[j] - 48;
      j--;
    }
    for (int i = 80; i != 0; i--) {
      ans[i] = ans[i] + a[i] + b[i];
      if (ans[i] >= 10) {
        ans[i] = ans[i] - 10;
        ans[i - 1]++;
      }
    }
    if (ans[0] != 11111) {
      cout << "overflow" << endl;
      continue;
    }
    for (int i = 1; i < 81; i++) {
      if (ans[i] != 0) {
        j = i;
        break;
      }
    }
    char c[3];
    for (int i = j; i < 81; i++) {
      printf("%c", ans[i] + 48);
    }
    cout << '\\n';
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

// 2012/10/28 Tazoe

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

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

  for (int i = 0; i < N; i++) {
    string S1, S2;
    cin >> S1;
    cin >> S2;

    if (S1.size() < S2.size()) {
      string tmp = S1;
      S1 = S2;
      S2 = tmp;
    }

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

    int A[80];
    int C = 0;
    for (int j = 0; j < S1.size(); j++) {
      int tmp = (int)(S1[S1.size() - 1 - j] - '0') + C;
      if (j < S2.size()) {
        tmp += (int)(S2[S2.size() - 1 - j] - '0');
      }

      A[j] = tmp % 10;
      C = tmp / 10;
    }

    if (S1.size() == 80 && C == 1) {
      cout << "overflow" << endl;
    } else {
      if (C == 1) {
        cout << C;
      }
      for (int j = S1.size() - 1; j >= 0; j--) {
        cout << A[j];
      }
      cout << endl;
    }
  }

  return 0;
}

Error: WA

Fixed submission:

// 2012/10/28 Tazoe

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

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

  for (int i = 0; i < N; i++) {
    string S1, S2;
    cin >> S1;
    cin >> S2;

    if (S1.size() < S2.size()) {
      string tmp = S1;
      S1 = S2;
      S2 = tmp;
    }

    int A[80];
    int C = 0;
    for (int j = 0; j < S1.size(); j++) {
      int tmp = (int)(S1[S1.size() - 1 - j] - '0') + C;
      if (j < S2.size()) {
        tmp += (int)(S2[S2.size() - 1 - j] - '0');
      }

      A[j] = tmp % 10;
      C = tmp / 10;
    }

    if (S1.size() == 80 && C == 1) {
      cout << "overflow" << endl;
    } else {
      if (C == 1) {
        cout << C;
      }
      for (int j = S1.size() - 1; j >= 0; j--) {
        cout << A[j];
      }
      cout << endl;
    }
  }

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    vector<int> ans;
    int k = 0;
    for (int j = 0; j < 1000; j++) {
      int num = 0;
      int a = s1.size() - 1 - j, b = s2.size() - 1 - j;
      if (a < 0 && b < 0 && k == 0)
        break;
      if (a >= 0)
        num += s1[a] - '0';
      if (b >= 0)
        num += s2[b] - '0';
      ans.pb((num + k) % 10);
      if (num + k >= 10)
        k = 1;
      else
        k = 0;
    }
    if (ans.size() > 80) {
      printf("overflow\\n");
      continue;
    }
    for (int j = ans.size() - 1; j >= 0; j--) {
      cout << ans[j];
    }
    cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
int main() {
  int n;
  cin >> n;
  for (int j = 0; j < n; j++) {
    string s1, s2;
    vector<int> ans;
    cin >> s1;
    cin >> s2;
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(), s2.end());
    int k = 0;
    int p = max(s1.size(), s2.size());
    int len1 = s1.size(), len2 = s2.size();
    s1.resize(p + 2);
    s2.resize(p + 2);
    for (int i = len1; i < p + 2; i++) {
      s1[i] = '0';
    }
    for (int i = len2; i < p + 2; i++) {
      s2[i] = '0';
    }
    ans.resize(p + 2);
    for (int i = 0; i < p + 2; i++) {
      ans[i] = ((s1[i] - '0') + (s2[i] - '0') + k) % 10;
      if ((s1[i] - '0') + (s2[i] - '0') + k >= 10)
        k = 1;
      else
        k = 0;
    }
    vector<int>::iterator it = ans.end();
    it--;
    int r = 0;
    while (*it == 0) {
      ans.erase(it);
      r++;
      it--;
    }
    ans.resize(p + 2 - r);
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

char n1[100], n2[100], ans[100];

void reverse(char n[100], int l, int r) {
  if (l >= r)
    return;
  swap(n[l], n[r]);
  reverse(n, l + 1, r - 1);
}

void sum(int n, int m) {
  int x1 = (n >= strlen(n1) ? 0 : n1[n] - '0');
  int x2 = (n >= strlen(n2) ? 0 : n2[n] - '0');
  int tmp = x1 + x2 + m;
  if (n == 100 || (n >= strlen(n1) && n >= strlen(n2) && m == 0))
    return;
  ans[n] = tmp % 10 + '0';
  sum(n + 1, tmp / 10);
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    fill(ans, ans + 99, '\\0');
    scanf("%s", n1);
    scanf("%s", n2);
    reverse(n1, 0, strlen(n1) - 1);
    reverse(n2, 0, strlen(n2) - 1);
    sum(0, 0);
    if (strlen(ans) > 80)
      printf("overflow\\n");
    else {
      reverse(ans, 0, strlen(ans) - 1);
      printf("%s\\n", ans);
    }
  }

  return 0;
}

Error: WA

Fixed submission:

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

char n1[100], n2[100], ans[100];

// n1とn2の和をansに入れる
void sum(int n, int m, int p1,
         int p2) { // n:桁目, m:繰り上がり, p1:n1の注目桁, p2:n2の注目点
  int tmp;
  if (p1 == -1 && p2 == -1) {
    if (m == 1)
      printf("1");
    return;
  }
  if (p1 == -1) {
    tmp = n2[p2] + m - '0';
    ans[n] = tmp % 10 + '0';
    sum(n - 1, (tmp > 9 ? 1 : 0), -1, p2 - 1);
    return;
  }
  if (p2 == -1) {
    tmp = n1[p1] + m - '0';
    ans[n] = tmp % 10 + '0';
    sum(n - 1, (tmp > 9 ? 1 : 0), p1 - 1, -1);
    return;
  }
  tmp = n1[p1] + n2[p2] + m - 2 * '0';
  ans[n] = tmp % 10 + '0';
  sum(n - 1, (tmp > 9 ? 1 : 0), p1 - 1, p2 - 1);
  return;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    fill(ans, ans + 99, '\\0');
    scanf("%s", n1), scanf("%s", n2);
    sum((strlen(n1) > strlen(n2) ? strlen(n1) - 1 : strlen(n2) - 1), 0,
        strlen(n1) - 1, strlen(n2) - 1);
    printf("%s\\n", ans);
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, i, j, k, s, t, u;
  int carry = 0;
  string a, b, d;
  vector<int> c;
  cin >> n;
  for (i = 0; i < n; i++) {
    c.clear();
    cin >> a;
    cin >> b;
    while (a.size() > b.size()) {
      b = "0" + b;
    }
    while (b.size() > a.size()) {
      a = "0" + a;
    }
    s = a.size();
    for (j = s - 1; j >= 0; j--) {
      t = a[j] - '0' + b[j] - '0';
      if (carry == 1) {
        carry = 0;
        t += 1;
      }
      while (t >= 10) {
        t -= 10;
        carry += 1;
      }
      c.push_back(t);
    }
    while (carry == 1) {
      carry = 0;
      c.push_back(1);
    }
    u = c.size();
    if (u > 80 || a.size() > 80 || b.size() > 80) {
      cout << "overflow" << endl;
    } else if (u <= 80) {
      for (k = u - 1; k >= 0; k--) {
        cout << c[k];
      }
      cout << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int N, a, b, c, d, f;
  int e = 0;
  string s, t, u;
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      if (j == 0) {
        cin >> s;
      } else if (j == 1) {
        cin >> t;
      }
    }
    a = s.size();
    b = t.size();
    if (a < b) {
      c = a;
    } else if (a >= b) {
      c = b;
    }
    for (int k = c; k >= 0; k++) {
      d = s[c - 1] + t[c - 1];
      while (e == 1) {
        e = 0;
        d += 1;
      }
      if (d < 10) {
        u[c - k] = d;
      } else {
        u[c - k] = d - 10;
        e = 1;
      }
    }
    f = u.size();
    while (f > 80) {
      cout << "overflow" << endl;
      break;
    }
    while (f <= 80) {
      for (int i2 = 0; i2 < f; i2++) {
        cout << u[f - 1 - i2];
      }
      break;
    }
  }
  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 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: WA

Fixed submission:


#include <iostream>
#include <string>

using namespace std;

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

    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 (p1 >= 0) {
      int bd = buf[pb];
      if (bd > 0)
        bd -= '0';
      int d = s1[p1--] - '0' + bd + carry;
      carry = d / 10;
      d %= 10;
      buf[pb--] = d + '0';
    }
    if (pb == -1 && carry > 0)
      cout << "overflow" << endl;
    else {
      if (carry > 0)
        buf[pb--] = carry + '0';
      cout << (char *)(buf + (pb + 1)) << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
// #define INF (1LL<<59)

string addString(string a, string b) {
  if (a.size() < b.size())
    swap(a, b); // len(a)>len(b)???
  b = string(a.size() - b.size(), '0') +
      b; // b????????????a??¨??????????????????????????????0??§?????????

  string ans =
      string(a.size() + 1, '0'); // a?????????+1 ?????????0??§???????????????
  for (int i = (int)a.size() - 1; i >= 0; i--) { //?¶??????? & ??°????????????
    ans[i + 1] += (a[i] - '0') + (b[i] - '0');
    if (ans[i + 1] >= '0' + 10) {
      ans[i] += 1;
      ans[i + 1] -= 10;
    }
  }
  string ret = ""; //??????????????°???0????¶????
  rep(i, ans.size()) {
    if (ans[i] != '0' || i == ans.size() - 1) {
      ret = ans.substr(i, ans.size() - i);
      break;
    }
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    string a, b;
    cin >> a >> b;
    string res = addString(a, b);
    if (res.size() > 80)
      cout << "overflow" << endl;
    else
      cout << res << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

#define dump(x) cerr << #x << " = " << (x) << endl
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define sz size()

const double EPS = 1e-10;
const int INF = 100000000;

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    string a, b;
    cin >> a >> b;
    if (a.sz > b.sz)
      swap(a, b);
    reverse(all(a));
    reverse(all(b));
    int k = b.sz - a.sz;
    rep(i, k) a += '0';

    int ans[100] = {};
    rep(i, b.sz) {
      ans[i] += a[i] - '0' + b[i] - '0';
      if (ans[i] >= 10) {
        ans[i] -= 10;
        ans[i + 1]++;
      }
    }
    if (ans[b.sz] && b.sz >= 80)
      cout << "overflow" << endl;
    else {
      if (ans[b.sz]) {
        cout << ans[b.sz];
      }
      for (int i = b.sz - 1; i >= 0; i--) {
        cout << ans[i];
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00015 (C++) — buggy submission, verdict: Runtime Error

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

int charToInt(char);
string sumStr(string, string);

int charToInt(char c) { return (int)c - (int)'0'; }

string sumStr(string a, string b) {
  int pa = a.length() - 1, pb = b.length() - 1;
  string str(83, '0');
  int pstr = str.length() - 1;
  int next = 0;
  while (pa >= 0 && pb >= 0) {
    int temp = charToInt(a[pa]) + charToInt(b[pb]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pa--;
    pb--;
    pstr--;
  }
  while (pa >= 0) {
    int temp = charToInt(a[pa]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pa--;
    pstr--;
  }
  while (pb >= 0) {
    int temp = charToInt(b[pb]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pb--;
    pstr--;
  }
  str[pstr] = (char)(next + (int)'0');

  for (int i = 0; i < str.length(); i++) {
    if (str[i] != '0') {
      return str.substr(i, str.length() - i);
    }
  }
  return "0";
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    bool overflow = false;
    int data[N][8];
    string sum;
    for (int j = 0; j < 2; j++) {
      string str;
      cin >> str;
      if (str.length() > 80)
        overflow = true;
      if (!overflow) {
        if (j == 0)
          sum = str;
        else
          sum = sumStr(sum, str);
        if (sum.length() > 80)
          overflow = true;
      }
    }

    if (overflow)
      cout << "overflow" << endl;
    else
      cout << sum << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int charToInt(char);
string sumStr(string, string);

int charToInt(char c) { return (int)c - (int)'0'; }

string sumStr(string a, string b) {
  int pa = a.length() - 1, pb = b.length() - 1;
  string str(83, '0');
  int pstr = str.length() - 1;
  int next = 0;
  while (pa >= 0 && pb >= 0) {
    int temp = charToInt(a[pa]) + charToInt(b[pb]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pa--;
    pb--;
    pstr--;
  }
  while (pa >= 0) {
    int temp = charToInt(a[pa]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pa--;
    pstr--;
  }
  while (pb >= 0) {
    int temp = charToInt(b[pb]) + next;
    next = temp / 10;
    str[pstr] = (char)(temp % 10 + (int)'0');

    pb--;
    pstr--;
  }
  str[pstr] = (char)(next + (int)'0');

  for (int i = 0; i < str.length(); i++) {
    if (str[i] != '0') {
      return str.substr(i, str.length() - i);
    }
  }
  return "0";
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    bool overflow = false;
    int data[N][8];
    string sum;
    for (int j = 0; j < 2; j++) {
      string str;
      cin >> str;

      if (!overflow) {
        if (j == 0)
          sum = str;
        else
          sum = sumStr(sum, str);
        if (sum.length() > 80)
          overflow = true;
      }
    }

    if (overflow)
      cout << "overflow" << endl;
    else
      cout << sum << endl;
  }
  return 0;
}