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

#include <cstdio>
int main() {
  int a, b, c;
  while (scanf("%d", &a) != EOF) {
    scanf(" %d", &b);
    c = a + b;
    int cnt, i;
    i = 1;
    for (cnt = 0;; cnt++) {
      if (c / i == 0)
        break;
      i = i * 10;
    }
    printf("%d\\n", cnt);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
int main() {
  for (;;) {
    int a, b, c;
    scanf("%d %d", &a, &b);
    if (a == EOF)
      break;
    c = a + b;
    int cnt, i;
    i = 1;
    for (cnt = 0;; cnt++) {
      if (c / i == 0)
        break;
      i = i * 10;
    }
    printf("%d\\n", cnt);
  }

  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 cnt = 1;
    for (int i = a + b; i >= 10; cnt++)
      i /= 10;

    cout << cnt << endl;
  }

  return (0);
}

Error: TLE

Fixed submission:

#include <cstdio>

using namespace std;

int main() {
  int a, b;

  while (scanf("%d%d", &a, &b), a != EOF) {
    int cnt = 1;
    for (int i = a + b; i >= 10; cnt++)
      i /= 10;

    printf("%d\\n", cnt);
  }

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

#include <iostream>
using namespace std;

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

  while (cin >> a >> b) {
    res = 0;
    sum = a + b;

    while (sum / 10 != 0) {
      sum /= 10;
      res++;
    }
    cout << res + 1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  while (cin >> a >> b) {
    res = 0;
    sum = a + b;

    while (sum / 10 != 0)
      res++;
    cout << res << endl;
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int a, b, c;
  while (~scanf("%d%d", &a, &b)) {
    c = 0;
    a += b;
    while (a) {
      a /= 10;
      c++;
    }
    printf("%d\\n", c);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  int a, b;
  while (scanf("%d%d", &a, &b)) {
    printf("%d\\n", a + b);
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int check_digit(int num) {
  int digit = 0;
  while (true) {
    num /= 10;
    digit++;
    if (num <= 0) {
      break;
    }
  }
  return digit;
}

int digit_count(int a, int b) {
  int digit;
  digit = check_digit(a + b);
  return digit;
}

int main(int argc, char const *argv[]) {
  int a, b;
  list<int> ls;
  while (!(std::cin >> a >> b).eof()) {
    ls.push_back(digit_count(a, b));
  }

  list<int>::iterator it = ls.begin();
  while (it != ls.end()) {
    cout << *it << endl;
    it++;
  }
}


Error: TLE

Fixed submission:

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

int check_digit(int num) {
  int digit = 0;
  while (true) {
    num /= 10;
    digit++;
    if (num <= 0) {
      break;
    }
  }
  return digit;
}

int digit_count(int a, int b) {
  int digit;
  digit = check_digit(a + b);
  return digit;
}

int main(int argc, char const *argv[]) {
  int a, b;
  list<int> ls;
  while (!std::cin.eof()) {
    std::cin >> a;
    std::cin >> b;
    ls.push_back(digit_count(a, b));
  }

  for (int i : ls) {
    std::cout << i << '\\n';
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace ::std;

int main() {
  int a, b, c;
  int keta;

  while (cin >> a) {
    cin >> b;
    c = a + b;
    keta = 1;
    while ((c /= 10) > 0)
      keta++;
    cout << keta << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

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

  while (scanf("%d %d", &a, &b) != EOF) {
    sum = a + b;
    count = 1;
    while (sum / 10 != 0)
      count++;
    printf("%d\\n", count);
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
int keta(int n) {
  static int cnt = 0;
  if (n > 0) {
    cnt++;
    return keta(n / 10);
  } else {
    return cnt;
  }
}
int main() {
  int a, b;
  int n;
  while (scanf("%d %d", &a, &b) != 1) {
    a += b;
    n = keta(a);
    cout << n << 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) {
    cout << (int)log10(a + b) + 1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int keta(int i) {
  if (i < 10) {
    return 0;
  } else {
    return 1 + keta(i / 10);
  }
}

int main() {
  int a, b;
  while (1) {
    cin >> a >> b;
    cout << keta(a) + keta(b);
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

int main() {
  int a, b;
  char temp[100];

  while (scanf("%d %d", &a, &b) != EOF) {
    printf("%d\\n", sprintf(temp, "%d", a + b));
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

int main() {
  int a, b;
  char temp[100];

  while (scanf("%d %d", &a, &b) != 0) {
    printf("%d\\n", sprintf(temp, "%d", a + b));
  }

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

#include <iostream>
using namespace std;

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

  while (1) {
    cin >> a >> b;
    if (cin.eof()) {
      break;
    }

    sum = a + b;

    for (int i = 1;; ++i) {
      if (sum < 10) {
        cout << i << endl;
        break;
      } else {
        sum /= 10;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

  while (1) {
    cin >> a >> b;
    sum = a + b;

    for (int i = 1;; ++i) {
      if (sum < 10) {
        cout << i << endl;
        break;
      } else {
        sum /= 10;
      }
    }
  }

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

#include <iostream>
#include <math.h>
using namespace std;

int main() {

  // 変数の宣言

  int a, b, sum, i = 0;

  /////メイン処理/////

  while (cin >> a >> b) {
    // 入力
    sum = a + b;
    // 桁数の計算

    while (1) {
      if (pow(10, i) <= sum && pow(10, i + 1) > sum) {
        cout << i + 1 << endl;
        break;
      }
      i++;
    }

    i = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;

int main() {

  // 変数の宣言

  int a, b, sum, i = 0;

  /////メイン処理/////

  while (cin >> a >> b) {
    // 入力
    sum = a + b;
    // 桁数の計算

    while (1) {
      if (pow(10, i) <= sum && pow(10, i + 1) > sum) {
        cout << i + 1 << endl;
        break;
      }
      i++;
    }
  }

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

#include <iostream>

using namespace std;

int main() {
  unsigned int a, b, c, ans = 0; // initializing numbers
  while (cin >> b >> c)          // entering 2 numbers
  {
    a = b + c; // adding the 2 numbers
    while (a != 0) {
      a /= 10;
      ans++; // dividing sum by 10 then adding ans by 1 for number of digits
    }
    cout << ans << endl; // print out how many digits
    ans = 0;
  }

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c = 0, d;
  while (cin >> a >> b) {
    a += b;
    while (a) {
      c++;
      a /= b;
    }
    cout << c << endl;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

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

  while (std::cin >> a >> b) {
    count = 0;
    tmp = a + b;
    while (tmp > 0) {
      count++;
      tmp /= 10;
    }
    std::cout << count << std::endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int a = 0;
  int b = 0;
  int ans = 0;
  while (scanf("%d,%d", a, b) != EOF) {
    a += b;
    while (1) {
      a /= 10;
      ans++;
      if (a = 0) {
        printf("%d", ans);
        break;
      }
    }
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a, b;
  while (scanf("%d %d", &a, &b) != EOF) {
    int sum = a + b, cnt = 1;
    while (sum /= 10)
      cnt++;
    cout << cnt << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int a, b;
  while (scanf("%d %d", &a, &b)) {
    int sum = a + b, cnt = 1;
    while (sum /= 10)
      cnt++;
    cout << cnt << endl;
  }
}
Problem p00002 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int sum, j;
  int i = 0;
  int N = 200;

  int a[N], b[N], dig[N];

  while (cin >> a[i] >> b[i]) {
    dig[i] = 1;
    if (0 <= a[i] && a[i] <= 1000000 && 0 <= b[i] && b[i] <= 1000000) {
      sum = a[i] + b[i];
      while (sum / 10 != 0) {
        sum = sum / 10;
        dig[i] += 1;
      }
      i++;
    }
  }

  for (j = 0; j < i; j++) {
    cout << dig[j] << "\\n";
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int sum, j;
  int i = 0;
  int N;

  cout << "How many date sets (N<=200) N=";
  cin >> N;
  int a[N], b[N], dig[N];

  while (i < N) {
    cout << "please input `a b' : ";
    cin >> a[i] >> b[i];
    dig[i] = 1;
    if (0 <= a[i] && a[i] <= 1000000 && 0 <= b[i] && b[i] <= 1000000) {
      sum = a[i] + b[i];
      while (sum / 10 != 0) {
        sum = sum / 10;
        dig[i] += 1;
      }
      i++;
    } else {
      cout << "error!\\n";
    }
  }

  for (j = 0; j < i; j++) {
    cout << dig[j] << "\\n";
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int getDigital(int sum) {
  int a = 1;
  while (sum / 10) {
    a++;
    sum /= 10;
  }
  return a;
}

int main() {
  int a, b, c;
  while (cin >> a >> b) {
    c = getDigital(a + b);
    cout << c << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int getDigital(int sum) {
  int a = 1;
  while (sum / 10) {
    a++;
    sum /= 10;
  }
  return a;
}

int main() {
  int a, b, c;
  while (1) {
    cin >> a >> b;
    c = getDigital(a + b);
    cout << c << endl;
  }
}
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) {
    a = log10(a + b) + 1;
    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int a, b;
  int ans = 0;
  while (true) {
    cin >> a >> b;
    ans = log10(a + b) + 1;
    cout << ans << endl;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long int a, b;
  int ans;
  while (scanf("%lld %lld", &a, &b) != EOF) {
    a += b;
    ans = 0;
    while (a > 0) {
      a = a / 10;
      ans++;
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

Error: TLE

Fixed submission:

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

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

int main() {
  int a, b, i = 10;
  while (cin >> a >> b) {
    for (int j = 1;; j++) {
      if (a + b < (int)pow(10, j)) {
        cout << j << endl;
        break;
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int a, b, c, su = 1000000;
  for (int i = 1; i <= 200; i++) {
    cin >> a >> b;
    while (a != -1 || b != -1) {
      c = a + b;
      if (c == 0) {
        cout << "0" << endl;
      } else {
        for (int j = 7; j >= 1; j--) {
          if (c >= su) {
            cout << j << endl;
            su = 1000000;
            break;
          } else {
            su /= 10;
          }
        }
      }
    }
  }

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

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

int main() {
  int a, b;
  while (scanf("%d %d", &a, &b) != EOF) {
    a += b;
    int ans = 0;
    while (a > 0) {
      a /= 10;
      ans++;
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a, b;
  while (true) {
    cin >> a >> b;
    int sum = a + b;
    int ans = 0;
    while (sum > 0) {
      sum /= 10;
      ans++;
    }
    printf("%d\\n", ans);
  }
  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) {
    cout << to_string(a + b).size() << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b;
  while (true) {
    cin >> a >> b;
    cout << to_string(a + b).size() << endl;
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

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

    cout << c << endl;
  }
  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 count = 0;
    int result = a + b;
    while (1) {
      if (result == 0) {
        cout << count << "\\n";
        break;
      }
      result /= 10;
      count++;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  while (1) {
    int a, b;
    cin >> a >> b;
    int count = 0;
    int result = a + b;
    while (1) {
      if (result == 0) {
        cout << count << "\\n";
        break;
      }
      result /= 10;
      count++;
    }
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

using namespace std;

int main() {
  int a, b, i;
  while (scanf("%d%d", &a, &b) != EOF) {
    a += b;
    for (i = 0; i < 201; i++) {
      if (a / 10 == 0) {
        printf("%d\\n", i + 1);
        break;
      } else {
        a = a / 10;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

using namespace std;

int main() {
  int a, b, i;
  while (a != -1 && b != -1) {
    scanf("%d%d", &a, &b);
    a += b;
    for (i = 0; i < 201; i++) {
      if (a / 10 == 0) {
        printf("%d\\n", i + 1);
        break;
      } else {
        a = a / 10;
      }
    }
  }

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


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

int main() {
  int a, b;

  while (cin >> a >> b) {
    int cnt = 1;
    int c = 10;
    for (int i = 0; i < 8; i++) {
      // cout << c << ' ' << cnt << endl;
      if ((a + b) - c < 0)
        break;
      // cout << a << ' ' << b << '=' << a+b << endl;
      cnt++;
      c *= 10;
    }
    cout << cnt << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int a, b;
  int cnt = 1;

  while (scanf(" %d %d", &a, &b)) {
    cnt = 1;
    int c = 10;
    for (int i = 1; i < 9; i++) {
      if ((a + b) - c <= 0)
        break;
      // cout << a << ' ' << b << '=' << a+b << endl;
      cnt++;
      c *= c;
    }
    cout << cnt << 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) {
    a = log10(a + b) + 1;
    cout << a << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int digit(int a, int b) {
  int sum = a + b;
  int d = 0;
  while (1) {
    sum /= 10;
    d++;
    if (sum == 0)
      break;
  }
  return d;
}

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


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int A[200];
  int B[200];
  int i;
  for (i = 0; i < 200; i++) {
    A[i] = -1;
    B[i] = -1;
  }
  for (i = 0; i < 200; i++) {
    cin >> A[i] >> B[i];
  }
  i = 0;
  int sum, digit;
  while (A[i] >= 0) {
    sum = A[i] + B[i];
    while (digit) {
      sum /= 10;
      digit++;
    };
    cout << digit << endl;
  };
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b) {
    a = a + b;
    cout << (int)log10(a) + 1 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {

  while (true) {
    int a, b;
    cin >> a >> b;
    a = a + b;
    cout << (int)log10(a) + 1 << endl;
  }

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

#include <iostream>
using namespace std;

int main(void) {
  int a, b, c, d, t;
  while (cin >> a >> b) {
    t = a + b;

    c = t / 1;
    if (c >= 1)
      d = 1;

    c = t / 10;
    if (c >= 1)
      d = 2;

    c = t / 100;
    if (c >= 1)
      d = 3;

    c = t / 1000;
    if (c >= 1)
      d = 4;

    c = t / 10000;
    if (c >= 1)
      d = 5;

    c = t / 100000;
    if (c >= 1)
      d = 6;

    c = t / 1000000;
    if (c >= 1)
      d = 7;

    cout << d << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int a, b, T, c, d, e, f, g, h, i, A = 0;
  while (1) {
    cin >> a >> b;
    T = a + b;

    c = T / 1000000;
    if (c >= 1)
      A = A + 1;

    d = T / 100000;
    if (d >= 1)
      A = A + 1;

    e = T / 10000;
    if (e >= 1)
      A = A + 1;

    f = T / 1000;
    if (f >= 1)
      A = A + 1;

    g = T / 100;
    if (f >= 1)
      A = A + 1;

    h = T / 10;
    if (h >= 1)
      A = A + 1;

    i = T / 1;
    if (i >= 1)
      A = A + 1;

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

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

int main() {
  int a, b, c;
  char str[16];
  while (cin >> a >> b) {
    c = sprintf(str, "%d", a + b);
    cout << c << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  while (true) {
    int a, b, c;
    char str[16];
    cin >> a >> b;

    c = sprintf(str, "%d", a + b);

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

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

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <iostream>
#include <vector>

#define ALL(a) a.begin(), a.end()

using namespace std;

int main() {
  unsigned a = 1, b;

  while (cin >> a >> b) {
    int c = 1, n = a + b;
    if (n == 0) {
      cout << 0 << endl;
      continue;
    }
    while (n /= 10)
      c++;
    cout << c << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

#define ALL(a) a.begin(), a.end()

using namespace std;

int main() {
  unsigned a = 1, b;

  while (a) {
    cin >> a >> b;
    int c = 1, n = a + b;
    while (n /= 10)
      c++;
    if (n == 0)
      cout << 0 << endl;
    else
      cout << c << endl;
  }

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

#include <iostream>
using namespace std;

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

  while (cin >> a >> b) {
    keta = 0;
    a += b;
    while (1) {
      a /= 10;
      if (a != 0) {
        keta++;
      } else {
        break;
      }
    }
    cout << (keta + 1) << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

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

  while (true) {
    cin >> a >> b;
    sum = a + b;

    char str[10];
    int keta = sprintf(str, "%d", sum);

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

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

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

Error: TLE

Fixed submission:

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