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

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

int main(void) {
  int i;
  int x, y;

  for (;;) {
    if (scanf("%d %d", &x, &y) == EOF) {
      break;
    }
    x += y;
    for (i = 1;; i++) {
      x /= 10;
      if (x == 0) {
        break;
      }
    }
    printf("%d\\n", i);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int i;
  int x, y;

  for (;;) {
    scanf("%d %d", &x, &y);
    x += y;
    for (i = 1;; i++) {
      x /= 10;
      if (x == 0) {
        break;
      }
    }
    printf("%d\\n", i);
  }

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

#include <iostream>
using namespace std;

int main() {
  int a, b, ans;
  while (cin >> a >> b) {
    a += b;
    ans = 0;
    while (a > 0, ans++, a /= 10)
      ;
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, ans;
  while (cin >> a >> b, a += b) {
    ans = 0;
    while (a > 0, ans++, a /= 10)
      ;
    cout << ans << endl;
  }

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

#include <stdio.h>
int main() {
  int a, b, c, i, count;
  while (scanf("%d%d", &a, &b) != EOF) {
    count = 1;
    if (a >= 0 && b >= 0) {
      c = a + b;
      for (i = 10; i <= c; i *= 10) {
        count++;
      }
      printf("%d\\n", count);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int a, b, c, i, count;
  while (scanf("%d%d", &a, &b)) {
    count = 1;
    if (a >= 0 && b >= 0) {
      c = a + b;
      for (i = 10; i <= c; i *= 10) {
        count++;
      }
      printf("%d\\n", count);
    }
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

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

int GetDigit(int num);

int main() {
  std::vector<int> r;
  while (true) {
    int nums[2];

    string str;
    int a = 0;
    getline(cin, str);
    string n[2];
    int nn[2];
    for (int i = 0; i < str.size(); ++i) {
      if (str[i] == ' ')
        a++;
      n[a] += str[i];
    }
    if (n[1].size() == 0)
      break;
    nn[0] = std::stoi(n[0]);
    nn[1] = std::stoi(n[1]);

    r.push_back(nn[0] + nn[1]);
  }

  for (int i = 0; i < r.size(); ++i) {
    printf("%d\\n", GetDigit(r[i]));
  }

  return 0;
}

int GetDigit(int num) {
  int digit = 0;
  while (num != 0) {
    num /= 10;
    ++digit;
  }
  return digit;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>
using namespace std;

int main() {
  std::vector<int> r;
  while (true) {
    int nums[2];
    for (int i = 0; i < 2; ++i) {
      scanf("%d", &nums[i]);
    }

    r.push_back(nums[0] + nums[1]);
  }

  for (int &i : r) {
    printf("%d\\n", i);
  }

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

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

#define MAX_NUMBER 200

using namespace std;

int main() {
  int num1, num2;
  char str[10];
  int i;

  while (cin >> num1 >> num2) {
    // 整形
    sprintf(str, "%d\\0", (num1 + num2));

    // 文字数計測
    for (i = 0; str[i] != '\\0'; i++) {
    }

    // 文字数表示
    cout << i << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  int num1, num2;
  char str[10];
  int i;

  while (1) {

    // 値の入力
    cin >> num1 >> num2;

    // 整形
    sprintf(str, "%d\\0", (num1 + num2));

    // 文字数計測
    for (i = 0; str[i] != '\\0'; i++) {
    }

    // 文字数表示
    cout << i << endl;
  }

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

#include <iostream>
using namespace std;
int main() {
  int a, b, i, s, ten = 1;
  while (cin >> a >> b) {
    s = a + b;
    for (i = 1; i < 8; i++) {
      ten = ten * 10;
      if (s / ten == 0) {
        cout << i << endl;
        break;
      }
    }
    ten = 1;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, i, s, ten = 1;
  while (1) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      break;
    s = a + b;
    for (i = 1; i < 8; i++) {
      ten = ten * 10;
      if (s / ten == 0) {
        cout << i << endl;
        break;
      }
    }
    ten = 1;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b) {
    int n = a + b;
    if (n > 999999) {
      cout << 7 << endl;
    } else if (n > 99999) {
      cout << 6 << endl;
    } else if (n > 9999) {
      cout << 5 << endl;
    } else if (n > 999) {
      cout << 4 << endl;
    } else if (n > 99) {
      cout << 3 << endl;
    } else if (n > 9) {
      cout << 2 << endl;
    } else {
      cout << 1 << endl;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  int a, b;
  while (true) {
  }
  int n = a + b;
  if (n > 99999) {
    cout << 6 << endl;
  } else if (n > 9999) {
    cout << 5 << endl;
  } else if (n > 999) {
    cout << 4 << endl;
  } else if (n > 99) {
    cout << 3 << endl;
  } else if (n > 9) {
    cout << 2 << endl;
  } else {
    cout << 1 << endl;
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define INT(name)                                                              \\
  int name;                                                                    \\
  scanf("%d", &name);
#define VINT(name, n)                                                          \\
  vector<int> name(n);                                                         \\
  for (int i = 0; i < n; i++)                                                  \\
    scanf("%d", &name[i]);

using namespace std;

int main(int argc, char const *argv[]) {
  int a, b;
  vector<int> answer;
  while (cin >> a >> b) {
    printf("%d\\n", (int)log10(a + b) + 1);
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define INT(name)                                                              \\
  int name;                                                                    \\
  scanf("%d", &name);
#define VINT(name, n)                                                          \\
  vector<int> name(n);                                                         \\
  for (int i = 0; i < n; i++)                                                  \\
    scanf("%d", &name[i]);

using namespace std;

int main(int argc, char const *argv[]) {
  int a, b;
  vector<int> answer;
  while (1) {
    cin >> a >> b;
    printf("%d\\n", (int)log10(a + b) + 1);
    if (cin.bad())
      break;
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main() {
  int x, y;
  while (cin >> x >> y) {
    x = x + y;
    stringstream a;
    a << x;
    string str = a.str();
    y = str.size();
    cout << y << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(void) {
  long long n, i, j, k;
  while (1) {
    cin >> j >> k;
    int x = j + k;
    stringstream str;
    str << x;
    string st = str.str();
    cout << st.size() << endl;
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {

  long a, b;

  while (cin >> a >> b) {
    long c = a + b;
    long d = 1;
    long e = 10;
    for (int j = 0; j < 10; j++) {
      if (c == 0) {
        cout << 1 << endl;
      } else if (c >= d && c < e) {
        cout << j + 1 << endl;
      }
      d = d * 10;
      e = e * 10;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {

  long a, b;

  while (1) {
    cin >> a >> b;

    long c = a + b;
    long d = 1;
    long e = 10;
    for (int j = 0; j < 10; j++) {
      if (c == 0) {
        cout << 1 << endl;
      } else if (c >= d && c < e) {
        cout << j + 1 << endl;
      }
      d = d * 10;
      e = e * 10;
    }
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int a, b;
  while (scanf("%d %d ", &a, &b) > 0) {
    a += b;
    b = 0;
    while (a > 0) {
      b++;
      a /= 10;
    }
    printf("%d\\n", (b ? b : 1));
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  int a, b;
  while (scanf("%d %d ", &a, &b)) {
    a += b;
    b = 0;
    while (a > 0) {
      b++;
      a /= 10;
    }
    printf("%d\\n", (b ? b : 1));
  }

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

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    a += b;
    a = (int)log10((double)a) + 1;

    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int a, b;
  while (1) {
    cin >> a >> b;
    a += b;
    a = (int)log10((double)a) + 1;

    cout << a << endl;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int a, b, sum, count;

  while (cin >> a >> b) {

    sum = a + b;
    count = 0;

    for (int i = sum; i >= 1; i = i / 10) {
      count++;
    }

    cout << count << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a, b, sum, count;

  while (cin >> a >> b) {

    sum = a + b;
    count = 0;

    for (int i = sum; i >= 1; i / 10) {
      count++;
    }

    cout << count << endl;
  }

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

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    int ans = log10(a + b) + 1;
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int a, b;
  while (1) {
    cin >> a;
    if (a == EOF)
      break;
    cin >> b;
    if (b == EOF)
      break;
    int ans = log10(a + b) + 1;
    cout << ans << endl;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b, sum, digit;
  while (cin >> a >> b) {
    digit = 0;
    sum = a + b;
    while (sum > 0) {
      sum /= 10;
      digit += 1;
    }
    cout << digit << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, sum, digit = 0;
  try {
    while (1) {
      digit = 0;
      cin >> a >> b;
      sum = a + b;
      while (sum > 0) {
        sum /= 10;
        digit++;
      }
      cout << digit;
    }
  } catch (...) {
    return 0;
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b) {
    int c = a + b;
    int i;
    for (i = 1; c > 0; i++) {
      c /= 10;
    }
    cout << i - 1 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int a, b;

    if (!cin >> a >> b)
      break;
    int c = a + b;
    int i;
    for (i = 1; c != 0; i++) {
      c /= 10;
    }
    cout << i << endl;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

void solve() {
  int a;
  while (cin >> a) {
    int b;
    cin >> b;
    int sum = a + b;
    int count = 0;
    while (sum) {
      sum /= 10;
      ++count;
    }
    cout << count << endl;
  }
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

void solve() {
  while (true) {
    int a, b;
    cin >> a >> b;
    int sum = a + b;
    int count = 0;
    while (sum) {
      sum /= 10;
      ++count;
    }
    cout << count << endl;
  }
}

int main() {
  solve();
  return (0);
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main() {
  int a, b, i;
  while (cin >> a >> b) {
    a += b;

    for (i = 1;; i++) {
      if (a < 10) {
        break;
      }
      a = a / 10;
    }

    cout << i << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  for (;;) {
    int a, b, i;

    scanf("%d%d", &a, &b);

    if (a == EOF || b == EOF) {
      break;
    }

    a += b;

    for (i = 1;; i++) {
      if (a < 10) {
        break;
      }
      a = a / 10;
    }

    cout << i << endl;
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
  int i, a, b, c;
  while (cin >> a >> b) {
    c = a + b;
    for (i = 1; c >= 10; i++) {
      c /= 10;
    }
    printf("%d\\n", i);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int i, a, b, c;
    cin >> a >> b;
    c = a + b;
    for (i = 0; c != 0; i++) {
      c /= 10;
    }
    if (i == 0)
      i = 1;
    cout << i << "\\n";
  }

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

#include <cstdio>
int main() {
  int d, n, a, b;
  while (true) {
    d = 0;
    if (scanf("%d %d", &a, &b) == EOF)
      break;
    n = a + b;
    while (n > 0) {
      d++, n /= 10;
    };
    printf("%d\\n", d);
  };
  return 0;
};

Error: TLE

Fixed submission:

#include <cstdio>
int main() {
  int d, n, a, b;
  while (true) {
    d = 0;
    if (scanf("%d %d", &a, &b) == 0)
      break;
    n = a + b;
    while (n > 0) {
      d++, n /= 10;
    };
    printf("%d\\n", d);
  };
  return 0;
};
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    int num = 1;
    int c = a + b;
    while (c / 10 != 0) {
      num++;
      c /= 10;
    }
    cout << num << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b, i = 0;
  while (cin >> a >> b, a + b != 0) {
    if (i == 199)
      break;
    int num = 1;
    int c = a + b;
    while (c / 10 != 0) {
      num++;
      c /= 10;
    }
    cout << num << endl;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;

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

int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;

string C;
string sA, strB;
vector<vector<char>> map;
vector<double> num;
vector<string> str;

int sum = 0;

vector<int> value;
vector<int> weight;

int dp[110][10010];

int data_[210][2] = {-2};

void input() {
  int i = 0;

  return;
}

int main(void) {
  input();
  int i = 0;
  int sum = 0;
  int numb = 0;
  int a = 0;
  int b = 0;

  while ((scanf("%d%d", &a, &b)) != EOF) {
    sum = a + b;
    while (sum != 0) {
      numb++;
      sum /= 10;
    }
    CO numb E numb = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;

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

int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;

string C;
string sA, strB;
vector<vector<char>> map;
vector<double> num;
vector<string> str;

int sum = 0;

vector<int> value;
vector<int> weight;

int dp[110][10010];

int data_[210][2] = {-2};

void input() {
  int i = 0;

  while (CI data_[i][0] >> data_[i][1]) {
    i++;
  }

  return;
}

int main(void) {
  input();
  int i = 0;
  int sum = 0;
  int numb = 0;

  while (true) {
    sum = data_[i][0] + data_[i][1];
    while (sum != 0) {
      numb++;
      sum /= 10;
    }
    if (data_[i + 1][0] == -2) {
      break;
    }
  }

  CO numb E

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

#include <cstdio>
int main() {
  int n, n1, n2, count, a;
  while (scanf("%d%d", &n1, &n2) != EOF) {
    count = 0;
    a = n1 + n2;
    while (a != 0) {
      a = a / 10;
      count++;
    }
    printf("%d\\n", count);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  char a, b;
  while (a = getchar() && a != EOF) {
    cin >> b;
    int sum = 0, c = a + b - 96;
    while (c != 0) {
      c = c / 10;
      sum++;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int c, g, a, b;
  while (scanf("%d%d", &a, &b) != EOF) {
    c = 0;
    g = a + b;
    while (1) {
      if (g / 10 >= 1)
        c++;
      else
        break;
      g /= 10;
    }
    cout << c + 1 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
  int c, g, a, b;
  while (1) {
    c = 0;
    cin >> a >> b;
    if (a == EOF && b == EOF)
      break;
    g = a + b;
    while (1) {
      if (g / 10 >= 1)
        c++;
      else
        break;
      g /= 10;
    }
    cout << c + 1 << endl;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#define ele long
using namespace std;
ele a, b;
inline ele d(ele x) {
  if (x == 0)
    return 1;
  ele s = 0;
  while (x > 0) {
    ++s;
    x /= 10;
  }
  return s;
}
int main() {
  while (~scanf("%d%d", &a, &b))
    printf("%d\\n", d(a + b));
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a, b, x;

  cin >> a >> b;
  int ar[7] = {1, 2, 3, 4, 5, 6, 7};
  while (a != -1) {
    int counter = -1;
    x = a + b;
    while (x != 0) {
      x /= 10;
      counter++;
    }
    cout << ar[counter] << endl;
    cin >> a >> b;
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <math.h>
#include <stdio.h>
int array[100];
int counter(long long int a, long long int b);
int main() {
  long long int a, b;
  int count;
  while (scanf("%lld %lld", &a, &b) == 2) {
    count = counter(a, b);
    printf("%d\\n", count);
  }
  return (0);
}
int counter(long long int a, long long int b) {
  long long int number;
  int x, count = 0;
  number = a + b;
  if (number == 0) {
    count = 1;
    return (count);
  } else {

    while (number != 0) {
      count++;
      number = number / 10;
    }
    return (count);
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

long n(int k) {
  if (k < 10 && k > 0)
    return 1;
  if (k >= 10 && k <= 99)
    return 2;
  if (k >= 100 && k <= 999)
    return 3;
  if (k >= 1000 && k <= 9999)
    return 4;
  if (k >= 10000 && k <= 99999)
    return 5;
  if (k >= 100000 && k <= 999999)
    return 6;

  return n(k);
}

int main() {

  int i, j, k;

  cin >> i;
  cin >> j;
  k = i + j;

  cout << n(i);
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main() {
  int a, b, dig, sum;
  while (scanf("%d %d", &a, &b) != EOF) {
    dig = 0;
    sum = a + b;
    while (sum) {
      dig++;
      sum = sum / 10;
    }
    printf("%d\\n", dig);
  }
  return 0;
}

Error: -6
6adaee1f-a29f-4882-b325-35332810688a.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p00002/C++/s445017591.cpp:19: int main(): Assertion `!fin.fail( )' failed.


Fixed submission:

#include <assert.h>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <iostream>

using namespace std;

#define set 200;
int main() {

  int a, b, sum;
  ifstream fin;

  fin.open("datasets.txt", ios::in);
  assert(!fin.fail());
  if (a >= 0 || b <= 1000000) {
    fin >> a >> b;
    while (!fin.eof()) {
      fin >> a >> b;
      cout << a << "\\t" << b << endl;
      cout << ceil(log10(a + b)) << endl;
    }

    fin.close();
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a, b, n, i, count;
  while (2 == scanf("%d %d", &a, &b)) {
    n = a + b;
    count = 0;
    while (n != 0) {
      i = n % 10;
      n /= 10;
      count++;
    }
    cout << count << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, sum, digit;
  while (1) {
    cin >> a >> b;
    sum = a + b;
    digit = 0;
    while (sum != 0) {
      sum /= 10;
      digit++;
    }
    cout << digit << "\\n";
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {

  int a = 0, b = 0;

  while (scanf("%d%d", &a, &b) != EOF) {

    if (a + b < 10) {
      printf("1\\n");
    } else if (a + b < 100) {
      printf("2\\n");
    } else if (a + b < 1000) {
      printf("3\\n");
    } else if (a + b < 10000) {
      printf("4\\n");
    } else if (a + b < 100000) {
      printf("5\\n");
    } else if (a + b < 1000000) {
      printf("6\\n");
    } else {
      printf("7\\n");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {

  int a = 0, b = 0;

  while (scanf("%d%d", &a, &b)) {

    if (a + b < 1000000) {
      printf("6\\n");
    } else if (a + b < 100000) {
      printf("5\\n");
    } else if (a + b < 10000) {
      printf("4\\n");
    } else if (a + b < 1000) {
      printf("3\\n");
    } else if (a + b < 100) {
      printf("2\\n");
    } else if (a + b < 10) {
      printf("1\\n");
    }
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {

  int a, b;
  int temp;
  int i = 0;
  int n;

  while (cin >> a >> b) {
    n = 0;
    temp = a + b;
    while (temp != 0) {
      n++;
      temp = temp / 10;
    }
    cout << n << "\\n";
    i++;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  int a, b;
  int temp;
  int i = 0;
  int j = 0;
  int n[200];

  while (cin >> a, b) {
    n[i] = 0;
    temp = a + b;
    while (temp != 0) {
      n[i]++;
      temp = temp / 10;
    }
    if (i == 199) {
      break;
    }
    i++;
  }

  while (cout << n[j]) {
    j++;
  }

  return 0;
}