alexjercan/bugnet huggingface dataset:
Problem p00001 (C++) — buggy submission, verdict: Runtime Error


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

using namespace std;

int main(void) {
  int i;
  int hs[10];

  for (i = 0; i < 10; i++) {
    cin >> hs[i];
  }

  sort(hs, hs + 10, greater<int>());

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

  return 0;
}

Error: -11

Fixed submission:


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

bool compare(int a, int b) { return a < b; }

int main(void) {
  int i;
  std::vector<int> hs(0, 10);

  for (i = 0; i < 10; i++) {
    std::cin >> hs[i];
  }

  std::sort(hs.begin(), hs.end(), std::greater<int>());

  for (i = 0; i < 3; i++) {
    std::cout << hs[i] << "\\n";
  }

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

#include <stdio.h>
int main(void) {
  int i, j, n[10], w;
  for (i = 0; i < 10; i++) {
    scanf("%d", &n[i]);
  }
  for (i = 0; i < 10; i++) {
    for (j = 0; j <= 10; j++) {
      if (n[j] <= n[i]) {
        w = n[i];
        n[i] = n[j];
        n[j] = w;
      }
    }
  }
  for (i = 0; i < 3; i++) {
    printf("%d\\n", n[i]);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>
int main(void) {
  int i, j, n[10], w;
  for (i = 0; i < 10; i++) {
    scanf("%d", n[i]);
  }
  for (i = 0; i < 10; i++) {
    for (j = 0; j <= 10; j++) {
      if (n[j] <= n[i]) {
        w = n[i];
        n[i] = n[j];
        n[j] = w;
      }
    }
  }
  for (i = 0; i < 3; i++) {
    printf("%d\\n", n[i]);
  }
  return 0;
}
Problem p00001 (C++) — buggy submission, verdict: Runtime Error

#include <cstdlib>
#include <fstream>
#include <iostream>

int main(int argc, char *argv[]) {
  //	std::ifstream datafile(argv[1]); //input datafile
  std::string str;
  int mt_height[10] = {}; // height of mountain
  int ans[3] = {}; // top 3 height of mountain. 0 -> no.1 1 -> no.2 2 -> no.3

  // if(datafile.fail()){
  // 	std::cout << "error : can't open this file." << std::endl;
  // 	exit(1);
  // }

  // input 10 height of mountain
  for (size_t i = 0; i < 10; i++) {
    std::getline(std::cin, str);
    sscanf(str.c_str(), "%d", &mt_height[i]);

    if ((mt_height[i] < 0) || (mt_height[i] > 10000)) {
      std::cout << "error : out of constraints" << std::endl;
      exit(1);
    }
  }

  // select top 3 height of mountain and sort ans[]
  for (size_t i = 0; i < 10; i++) {
    if (ans[0] < mt_height[i]) {
      ans[2] = ans[1];
      ans[1] = ans[0];
      ans[0] = mt_height[i];
    } else if (ans[1] < mt_height[i]) {
      ans[2] = ans[1];
      ans[1] = mt_height[i];
    } else if (ans[2] < mt_height[i]) {
      ans[2] = mt_height[i];
    }
  }

  // output ans[]
  for (size_t i = 0; i < 3; i++) {
    std::cout << ans[i] << std::endl;
  }

  return 0;
}

Error: 1

Fixed submission:

#include <cstdlib>
#include <fstream>
#include <iostream>

int main(int argc, char *argv[]) {
  std::ifstream datafile(argv[1]); // input datafile
  std::string str;
  int mt_height[10] = {}; // height of mountain
  int ans[3] = {}; // top 3 height of mountain. 0 -> no.1 1 -> no.2 2 -> no.3

  if (datafile.fail()) {
    std::cout << "error : can't open this file." << std::endl;
    exit(1);
  }

  // input 10 height of mountain
  for (size_t i = 0; i < 10; i++) {
    std::getline(datafile, str);
    sscanf(str.c_str(), "%d", &mt_height[i]);

    if ((mt_height[i] < 0) || (mt_height[i] > 10000)) {
      std::cout << "error : out of constraints" << std::endl;
      exit(1);
    }
  }

  // select top 3 height of mountain and sort ans[]
  for (size_t i = 0; i < 10; i++) {
    if (ans[0] < mt_height[i]) {
      ans[2] = ans[1];
      ans[1] = ans[0];
      ans[0] = mt_height[i];
    } else if (ans[1] < mt_height[i]) {
      ans[2] = ans[1];
      ans[1] = mt_height[i];
    } else if (ans[2] < mt_height[i]) {
      ans[2] = mt_height[i];
    }
  }

  // output ans[]
  for (size_t i = 0; i < 3; i++) {
    std::cout << ans[i] << std::endl;
  }

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

#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;
int main() {
  int a[10];
  for (int i = 0; i <= 9; i++)
    std::cin >> a[i];
  std::sort(a, a + 10, greater<int>());
  for (int j = 0; j < 3; j++) {
    std::cout << a[j] << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>

using namespace std;

int main() {
  int a[9];
  for (int i = 0; i <= 9; i++)
    std::cin >> a[i];
  std::sort(a, a + 10, greater<int>()); // ツソツーツトツつキツづゥツ。
  for (int j = 0; j < 3; j++) {
    std::cout << a[j]
              << ", "; // ツ個仰嘉環づーツプツδ環δ督トツつオツづづ敖づゥツ。
  }
  return 0;
}
Problem p00001 (C++) — buggy submission, verdict: Time Limit Exceeded

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

void bubbleSort(vector<int> &h) {
  int tmp;
  for (int i = 0; i < h.size() - 1; i++) {
    for (int j = 0; j < h.size() - 1 - i; j++) {
      if (h[j] < h[j + 1]) {
        tmp = h[j + 1];
        h[j + 1] = h[j];
        h[j] = tmp;
      }
    }
  }
}

int main() {
  vector<int> height(10);
  for (int i = 0; i < 10; i++) {
    cin >> height[i];
  }
  bubbleSort(height);
  for (int i = 0; i < 3; i++) {
    cout << height[i] << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

void bubbleSort(vector<int> &h) {
  int tmp;
  for (int i = 0; i < h.size() - 1; i++) {
    for (int j = 0; j < h.size() - 1 - i; j++) {
      if (h[j] < h[j + 1]) {
        tmp = h[j + 1];
        h[j + 1] = h[j];
        h[j] = tmp;
      }
    }
  }
}

int main() {
  vector<int> height(10);
  for (int i = 0; i < 10; i++) {
    cin >> height[i];
  }
  bubbleSort(height);
  for (int i : height) {
    cout << i << endl;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> ivector;

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

  return 0;
}

Error: -11

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> ivector;

int main() {
  int a, b;
  while (scanf("%d,%d", a, b) != EOF) {
    int dat = log10(a + b);
    cout << dat << endl;
  }

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

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

using namespace std;

int main(int argc, char *argv[]) {
  int a, b;
  while (cin >> a >> b) {
    int sum = a + b;
    int cnt = 1;
    while (sum /= 10) {
      cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;

int main(int argc, char *argv[]) {
  int a, b;
  while (cin >> a >> b) {
    int sum = a + b;
    int cnt = 1;
    while (sum / 10) {
      cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, b, i = 1;
  while (1) {
    scanf("%d %d", &a, &b);
    a = a + b;
    for (i = 1; i < 8; i++) {
      if (a < 10)
        break;
      a = a / 10;
    }
    printf("%d\\n", i);
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Runtime Error

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

  int len[200];
  int max = 0;
  for (int num = 0; num < 200; num++) {
    string str;
    string item;
    vector<string> list;
    getline(cin, str);
    if (str == "") {
      break;
    }

    stringstream ss(str);
    while (getline(ss, item, ' ') && !item.empty()) {
      list.push_back(item);
    }
    int sum = stoi(list[0].c_str()) + stoi(list[1].c_str());
    int count = 0;
    for (int i = 10; i <= 10000000; i = i * 10) {
      count++;
      if (sum < i) {
        len[num] = count;
        max++;
        break;
      }
    }
  }
  for (int num = 0; num < max; num++) {
    cout << len[num] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

  string str;
  do {

    string item;
    vector<string> list;
    getline(cin, str);

    stringstream ss(str);
    while (getline(ss, item, ' ') && !item.empty()) {
      list.push_back(item);
    }
    int sum = stoi(list[0].c_str()) + stoi(list[1].c_str());
    int count = 0;
    for (int i = 10; i <= 1000000; i = i * 10) {
      count++;
      if (sum < i) {
        cout << count << endl;
        break;
      }
    }
  } while (str != "");
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define MOD 1000000007 // 10^9+7
#define INF 1000000000 // 10^9

int main() {
  string str;
  while (getline(cin, str)) {
    bool f = 0;
    int a = 0, b = 0;
    for (int i = 0; i < (int)str.length(); i++) {
      if (str[i] == ' ')
        f = 1;
      else if (!f)
        a = a * 10 + (str[i] - '0');
      else
        b = b * 10 + (str[i] - '0');
    }
    cout << (int)log10(a + b) + 1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define MOD 1000000007 // 10^9+7
#define INF 1000000000 // 10^9

int main(int argc, const char *argv[]) {
  double a, b;
  while (1) {
    cin >> a >> b;
    if (a == 0 && b == 0)
      return 0;
    int k = log10(a + b) + 1;
    cout << k;
  }
}
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 i = 0;
    while (a > 0) {
      a /= 10;
      i++;
    }

    cout << i << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;
int main() {
  int a, b;
  while (true) {
    cin >> a >> b;
    if (a == EOF) {
      return 0;
    }
    a += b;
    int i = 0;
    while (a > 0) {
      a /= 10;
      i++;
    }

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

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

int main() {
  int a, b;
  while (cin >> a) {
    cin >> b;
    int sum = a + b;
    stringstream ss;
    ss << sum;
    string str(ss.str());
    cout << str.size() << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int a, b;
  while (1) {
    cin >> a;
    if (a < 0) {
      break;
    }
    cin >> b;
    auto sum = a + b;
    string str(to_string(sum));
    cout << str.size();
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <cstdio>
int main() {
  int a, b;
  char s[256], cmd[256];
  while (1) {
    fgets(s, 256, stdin);
    sscanf(s, "%s", cmd);
    if (cmd == "EOF") {
      break;
    }

    sscanf(s, "%d %d", &a, &b);
    int c = a + b, counter = 0;
    while (((int)c / 10) >= 1) {
      counter++;
      c = (int)c / 10;
    }

    printf("%d\\n", counter + 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 digit = log10(a + b) + 1;
    cout << digit << endl;
  }
}

Error: TLE

Fixed submission:

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

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

#include <iostream>
using namespace std;
class DigitNumber {
public:
  void solve(int a, int b) {
    string sum = to_string(a + b);
    if (sum == "0")
      cout << 0 << endl;
    else
      cout << sum.length() << endl;
  }
};
int main() {
  DigitNumber inst;
  int a, b;
  while (cin >> a >> b) {
    inst.solve(a, b);
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
class DigitNumber {
public:
  void solve(int a, int b) {
    string sum = to_string(a + b);
    if (sum == "0")
      cout << 0 << endl;
    else
      cout << sum.length() << endl;
  }
};
int main() {
  DigitNumber inst;
  int a, b;
  while (true) {
    cin >> a >> b;
    inst.solve(a, b);
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <math.h>
#include <stdio.h>

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

  while (scanf("%d %d", &a, &b) != EOF) {
    for (i = 0, x = a + b; x >= 1; x /= 10, i++)
      ;
    printf("%d\\n", i);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int main(void) {
  int sum = 0;
  char a;

  while (1) {
    sum = 0;
    while (scanf("%c", &a), a != ' ')
      sum++;
    while (scanf("%c", &a), a != '\\n')
      sum++;
    printf("%d\\n", sum);
  }

  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 = 0;
    while (c != 0) {
      i++;
      c /= 10;
    }
    cout << i << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

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

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
  int a, b, c;
  char ans[100];
  while (cin >> a >> b) {
    sprintf(ans, "%d", a + b);
    c = strlen(ans);
    cout << c << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
  int a, b, c;
  char ans[100];
  while (1) {
    cin >> a >> b;
    sprintf(ans, "%d", a + b);
    c = strlen(ans);
    cout << c << endl;
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

Error: TLE

Fixed submission:

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

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

// ------------------------------------
// Date:2018/ 2/11
// Problem:0002 : DigitNumber 2.cpp
//
// ------------------------------------

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

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

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


Error: TLE

Fixed submission:

// ------------------------------------
// Date:2018/ 2/11
// Problem:0002 : DigitNumber 2.cpp
//
// ------------------------------------

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

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

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

#include <cstdio>
using namespace std;
int main() {
  int a, b;
  while (scanf("%d %d", &a, &b) != EOF) {
    char c[255];
    printf("%d\\n", sprintf(c, "%d", a + b));
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;
int main() {
  int a, b;
  while (scanf("%d %d", &a, &b)) {
    char c[255];
    printf("%d\\n", sprintf(c, "%d", a + b));
  }
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main(void) {
  unsigned long int i, j, sum;
  unsigned int count = 0;
  while (1) {
    if (scanf("%ld %ld", &i, &j) == EOF)
      break;

    sum = i + j;
    count = 0;
    for (unsigned long int dec = 10; dec <= 1000000; dec *= 10) {
      if (sum < dec)
        break;
      count++;
    }
    printf("%d\\n", count + 1);
  }
  return 0;
}

Error: TLE

Fixed submission:

/*****include*****/
#include <fstream>
#include <iostream>

/*****デバッグ定義*****/
// #define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main() {
  /*****ファイルオープン*****/
#ifdef DEBUG
  ofstream fout("output.txt");
  ifstream fin("input.txt");
  if (!fout || !fin) {
    cout << "Can't open the file.\\n";
    return;
  }
#endif
  /*****変数置き場*****/
  int int_a, int_b;
  int num;
  while (1) {
    num = 0;
    cin >> int_a >> int_b;
    int_a += int_b;
    while (int_a / 10 != 0) {
      int_a = int_a / 10;
      num++;
    }
    cout << num + 1 << endl;
  }
  /*****処理部*****/

  /*****処理終了後*****/
#ifdef DEBUG
  fout.close();
  fin.close();
#endif
  return 0;
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {

  int a, b;
  int s, k;

  while (cin >> a >> b) {
    s = a + b;
    k = 0;
    while (s != 0) {
      s = s / 10;
      k++;
    }
    cout << k << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  int a, b;
  int s, k = 0;

  while (1) {
    cin >> a >> b;
    if (a < 0 || b < 0)
      break;
    s = a + b;
    while (s != 0) {
      s = s / 10;
      k++;
    }
    cout << k << endl;
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

// 泥臭いなあ
#include <cstdio>
#include <iostream>

int main() {
  using namespace std;
  long int a, b;
  unsigned long int div;

  while (cin >> a >> b) {

    div = (a + b) / 10;

    if (div == 0)
      cout << 1 << "\\n";
    else if (1 <= div && div <= 9)
      cout << 2 << "\\n";
    else if (10 <= div && div <= 99)
      cout << 3 << "\\n";
    else if (100 <= div && div <= 999)
      cout << 4 << "\\n";
    else if (1000 <= div && div <= 9999)
      cout << 5 << "\\n";
    else if (10000 <= div && div <= 99999)
      cout << 6 << "\\n";
    else if (100000 <= div && div <= 200000)
      cout << 7 << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

// 泥臭いなあ
#include <cstdio>
#include <iostream>

int main() {
  using namespace std;
  long int a, b;
  unsigned long int div;

  while (1) {

    cin >> a;
    if (a == EOF)
      break;
    cin >> b;
    div = (a + b) / 10;

    if (div == 0)
      cout << 1 << "\\n";
    else if (1 <= div && div <= 9)
      cout << 2 << "\\n";
    else if (10 <= div && div <= 99)
      cout << 3 << "\\n";
    else if (100 <= div && div <= 999)
      cout << 4 << "\\n";
    else if (1000 <= div && div <= 9999)
      cout << 5 << "\\n";
    else if (10000 <= div && div <= 99999)
      cout << 6 << "\\n";
    else if (100000 <= div && div <= 200000)
      cout << 7 << "\\n";
  }

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a, b, c, ans;

  while (cin >> a >> b) {
    c = a + b;
    ans = (int)log10((double)c) + 1;
    cout << ans << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int a, b, c, ans;

  while (1) {
    cin >> a >> b;
    c = a + b;
    ans = (int)log10((double)c) + 1;
    cout << ans << "\\n";
  }
}
Problem p00002 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES

#include <algorithm> // max??¢??°??????
#include <cmath>     // ??°??????
#include <fstream>   // ??????????????\\??????
#include <iomanip>   // stream???????????¢???
#include <iostream>  // ?¨??????\\??????
#include <string>    // ???????????¢???
#include <vector>    // ???????????????

using std::cin;
using std::cout;
using std::endl;
using std::fixed; // ???????????????????¨???????????????????????????????
using std::
    setprecision; // ?????°????°???°?????\\???????????°????????????????????¨????????\\???
using std::string;
using std::vector; // ????´???°????????????????????????

int main() {
  int a, b, c;
  int count;
  while (cin >> a >> b) {
    // ??\\???
    c = a + b;
    count = 0;

    // ?????°??????
    do {
      c = c / 10;
      count++;
    } while (c > 0);
    cout << count << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES

#include <algorithm> // max??¢??°??????
#include <cmath>     // ??°??????
#include <fstream>   // ??????????????\\??????
#include <iomanip>   // stream???????????¢???
#include <iostream>  // ?¨??????\\??????
#include <string>    // ???????????¢???
#include <vector>    // ???????????????

using std::cin;
using std::cout;
using std::endl;
using std::fixed; // ???????????????????¨???????????????????????????????
using std::
    setprecision; // ?????°????°???°?????\\???????????°????????????????????¨????????\\???
using std::string;
using std::vector; // ????´???°????????????????????????

int main() {
  int a, b, c;
  int count;
  while (true) {
    // ??\\???
    cin >> a >> b;
    c = a + b;
    count = 0;

    // ?????°??????
    do {
      c = c / 10;
      count++;
      cout << c << endl;
    } while (c > 0);
    cout << count << endl;
  }

  return 0;
}