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

#include <iostream>
using namespace std;

void check_num(int *i, int *x, int *n, int *flag);
void include3(int *i, int *x, int *n, int *flag);
void end_check_num(int *i, int *x, int *n, int *flag);

void call(int n) {
  int i = 1;
  int x = 0;
  int END_FLAG = 0;
  check_num(&i, &x, &n, &END_FLAG);
}

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

  return 0;
}
void check_num(int *i, int *x, int *n, int *flag) {
  *x = *i;
  if (*x % 3 == 0) {
    cout << " " << *i;
    end_check_num(i, x, n, flag);
  } else
    include3(i, x, n, flag);
}
void include3(int *i, int *x, int *n, int *flag) {
  if (*flag == 0) {
    if (*x % 10 == 3) {
      cout << " " << *i;
      end_check_num(i, x, n, flag);
    } else {
      (*x) /= 10;
      if (*x)
        include3(i, x, n, flag);
      else
        end_check_num(i, x, n, flag);
    }
  }
}
void end_check_num(int *i, int *x, int *n, int *flag) {
  if (++(*i) <= *n)
    check_num(i, x, n, flag);
  else {
    cout << endl;
    *flag = 1;
  }
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
void call_sub(int n, int i) {
  do {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      do {
        if (x % 10 == 3) {
          cout << " " << i;
          call_sub(n, i);
        }
      } while ((x /= 10) != 0);
    }
  } while (++i <= n);

  cout << endl;
}

int main(void) {
  int n;
  cin >> n;
  call_sub(n, 1);

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

#include <stdio.h>
int main() {
  int x, t;
  scanf("%d", &x);
  for (int i = 2; i <= x; i++) {
    if (i % 3 == 0)
      printf(" %d", i);
    else {
      t = i;
      while (1) {
        if (t % 10 == 3) {
          printf(" %d", i);
          break;
        }
        t = t / 10;
        if (t == 0)
          break;
      }
    }
  }
  printf("\\n");
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int x;

  scanf("%d", &x);
  for (int i = 2; i <= x; i++) {
    if (i % 3 == 0)
      printf(" %d", i);
    else if (i % 10 == 3)
      printf(" %d", i);
    else if (i = 3)
      printf(" %d", i);
  }
  printf("\\n");

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

#include <iostream>

using namespace std;

void call(int n) {
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    while (x) {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  call(n);
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

void call(int n) {

  for (int i = 1; i <= n; i++) {

    int x = i;

    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }

    while (true) { // while??????????????¨?????????????????¶????°?????????????
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    }
  }

  cout << endl;
}

int main() {

  int n;

  cin >> n;

  call(n);

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

#include <iostream>
using namespace std;

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

  for (int i = 1; i <= n; i++) {
    x = i;
    if (x % 3 == 0)
      cout << " " << i;
    else {
      do {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
      } while (x > 0);
    }
  }
  cout << "\\n";
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int i;
  int x, n;
  cin >> n;
  for (i = 1; i <= n; i++) {
    while (x)
      x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      break;
    } else if (x % 10 == 3) {
      cout << " " << i;
      break;
    }
    x /= 10;
    if (10 > x)
      break;
  }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)
using namespace std;

bool f(int x) {
  if (x == 0)
    return 0;
  if (x % 10 == 3)
    return 1;
  else
    f(x /= 10);
}

int main() {
  int n;
  cin >> n;
  rep(i, 1, n + 1) {
    if (i % 3 == 0)
      cout << " " << i;
    else if (f(i) == 1)
      cout << " " << i;
  }
  cout << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)

void f(int x) {
  if (x == 0)
    return;
  if (x == 3) {
    cout << " " << x;
    return;
  }
  x %= 10;
  f(x);
}

int main() {
  int n;
  cin >> n;
  rep(i, 1, n + 1) { f(i); }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

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

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

  for (int i = 1; i <= n; ++i) {
    x = i;
    if (i % 3 == 0) {
      cout << " " << i;
      continue;
    }

    while (x) {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  printf("\\n");
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

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

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

  for (int i = 1; i <= n; ++i) {
    x = i;
    if (i % 3 == 0) {
      cout << " " << i;
      continue;
    }

    while (x) {
      if (i % 10 == 3) {
        cout << " " << i;
        continue;
      }
      x /= 10;
    }
  }
  printf("\\n");
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a;
  cin >> a;
  for (int i = 1; i <= a; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else if (i % 10 == 3) {
      cout << " " << i;
    } else if ((i / 10) % 10 == 3) {
      cout << " " << i;
    } else if ((i / 100) % 10 == 3) {
      cout << " " << i;
    } else if ((i / 1000) % 10 == 3) {
      cout << " " << i;
    }
    if (i == a) {
      cout << "\\n";
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a;
  cin >> a;
  for (int i = 1; i <= a; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      for (int j = 0;; j++) {
        if (i == 0)
          break;
        if (i % 10 == 3) {
          cout << " " << i;
        } else {
          i = i / 10;
        }
      }
    }
  }
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int i, n, x;
  cin >> n;
  for (i = 1; i <= n; i++) {
    x = i;
    if (i % 3 == 0)
      cout << " " << i;
    else {
      while (x != 0) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
      }
    }
  }
  cout << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int i, n, o;
  o == 1;
  cin >> n;
  for (i = 1; i <= n; i++) {
    if (i % 3 == 0)
      cout << " " << i;
    while (i / o != 0) {
      if ((i / o) % 10 == 3)
        cout << " " << i;
      o *= 10;
    }
  }
  cout << endl;
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, x;
  cin >> n;
  for (x = 1; x < 10001; x++) {
    if (x > n)
      break;
    if (x % 3 == 0)
      cout << " " << x;
    else if (x % 10 == 3)
      cout << " " << x;
    else if ((x / 10) % 10 == 3)
      cout << " " << x;
    else if ((x / 100) % 10 == 3)
      cout << " " << x;
    else if ((x / 1000) % 10 == 3)
      cout << " " << x;
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, i, x, j;
  cin >> n;
  for (i = 1; i < n + 1; i++) {
    x = i / 10;
    if (i % 3 == 0)
      cout << " " << i;
    else if (i % 10 == 3)
      cout << " " << i;
    else if (x == 3)
      cout << " " << i;
    else {
      for (int j = 10; j < 1001; j * 10) {
        if (x / j == 3)
          cout << " " << i;
        else if (x % j == 3)
          cout << " " << i;
      }
    }
  }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, x;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      x = i;
      while (x > 0) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        } else {
          x = x / 10;
        }
      }
    }
  }
  cout << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, x;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      x = i;
      while (x > 0) {
        if (x % 10 == 3) {
          cout << " " << i;
        } else {
          x = x / 10;
        }
      }
    }
  }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
using namespace std;
// printf("%d %d %.5lf\\n",d,r,f);
int main() {
  int i;
  int x = 0;
  int y = 0;
  int z = 0;
  // while(1){
  scanf("%d", &i);
  while (++x <= i) {
    z = 0;
    y = x;
    if (x % 3 == 0) {
      printf(" %d", x);
    } else {
      while (y > 0) {
        if (y % 10 == 3 && z == 0) {
          printf(" %d", x);
          z = 1;
        }
        y = y / 10;
      }
    }
  }
  printf("\\n");
  x = 0;
  // }//1
} // main


Error: TLE

Fixed submission:

#include <stdio.h>
using namespace std;
// printf("%d %d %.5lf\\n",d,r,f);
int main() {
  int i;
  int x = 0;
  while (scanf("%d", &i)) {

    while (++x <= i) {
      if (x % 3 == 0) {
        printf("%d ", x);
      } else {
        if (x % 10 == 3)
          printf("%d ", x);
      }
    }
    printf("\\n");
    x = 0;
  } // 1
} // main
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

void call(int n) {

  int i = 1;
  do {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      do {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
      } while (x);
    }
    i++;
  } while (i <= n);
  cout << endl;
}

int main() {
  int n = 0;
  cin >> n;
  call(n);

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

void call(int n) {

  int i = 1;
  do {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    do {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    } while (x);
    i++;
  } while (i <= n);
  cout << endl;
}

int main() {
  int n = 0;
  cin >> n;
  call(n);

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

#include <iostream>

using namespace std;

int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      while (x > 0) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x = x / 10;
      }
    }
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      while (x >= 0) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x = x / 10;
      }
    }
  }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, x;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      x = i;
      while (x) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        } else {
          x = x / 10;
        }
      }
    }
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      while (i) {
        if (i % 10 == 3) {
          cout << " " << i;
          break;
        } else {
          i /= 10;
        }
      }
    }
  }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int main() {
  int n;
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (i % 3 == 0) {
      std::cout << " " << i;
      continue;
    } else
      while (x) {
        if (x % 10 == 3) {
          std::cout << " " << i;
          break;
        }
        x /= 10;
      }
  }
  std::cout << std::endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int main() {
  int n;
  std::cin >> n;
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (i % 3 == 0) {
      std::cout << " " << i;
      continue;
    } else
      while (x) {
        if (x % 10 == 3) {
          std::cout << " " << i;
          continue;
        }
        x /= 10;
      }
  }
  std::cout << std::endl;
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main(void) {
  int n;

  cin >> n;

  for (int i = 1; i < n + 1; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      int x = i;
      while (x != 0) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
      }
    }
  }

  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int n, i = 1;

  cin >> n;

  while (true) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      if (x % 10 == 3) {
        cout << " " << i;
      } else {
        x /= 10;
        if (x) {
          while (true) {
            if (x % 10 == 3) {
              cout << " " << i;
            } else {
              x /= 10;
              if (x)
                continue;
              else
                break;
            }
          }
        };
      }
    }

    if (++i <= n)
      continue;
    else
      break;
  }

  cout << endl;

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


#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      for (int x = i; x != 0; x /= 10) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
      }
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

void call(int n) {
  int i = 1;
  while (i <= n) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else if (i % 10 == 3) {
      cout << " " << i;
    } else {
      int x = i / 10;
      while (x >= 1) {
        if (i % 3 == 0) {
          cout << " " << i;
        } else if (i % 10 == 3) {
          cout << " " << i;
        }
      }
    }
    i++;
  }
  cout << endl;
}

int main() {
  int x = 0;
  cin >> x;
  call(x);
}
Problem p02406 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  long n, q[10000];

  cin >> n;

  for (long i = 1; i < n + 1; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
      q[i] = -1;
    } else if (i % 10 == 3) {
      cout << " " << i;
      q[i] = -1;
    }

    ostringstream p;
    p << i;
    string pp;
    pp = p.str();
    int k = 0;
    k = pp.size();
    for (int j = 0; j < k; j++) {
      if (pp.substr(j, 1) == "3" && q[i] != -1) {
        cout << " " << i;
        break;
      }
    }
  }
  cout << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;

int main(void) {
  long n, q[1000];

  cin >> n;

  for (long i = 1; i < n + 1; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
      q[i] = -1;
    } else if (i % 10 == 3) {
      cout << " " << i;
      q[i] = -1;
    }

    ostringstream p;
    p << i;
    string pp;
    pp = p.str();
    int k = 0;
    k = pp.size();
    for (int j = 0; j < k; j++) {
      if (pp.substr(j, 1) == "3" && q[i] != -1) {
        cout << " " << i;
        break;
      }
    }
  }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

void nabeatsu(int n) {
  int x;
  for (int i = 1; i <= n; i++) {
    x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else if (x % 10 == 3) {
      cout << " " << i;
    } else {
      x /= 10;
      if (x % 10 == 3) {
        cout << " " << i;
      } else if (x / 10 % 10 == 3) {
        cout << " " << i;
      } else if (x / 100 % 10 == 3) {
        cout << " " << i;
      }
    }
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  nabeatsu(n);
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

void nabeatsu(int n) {
  int x;
  for (int i = 1; i <= n; i++) {
    x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else if (x % 10 == 3) {
      cout << " " << i;
    } else {
      x /= 10;
      if (x % 10 == 3) {
        cout << " " << i;
      } else if (x / 10 % 10 == 3) {
        cout << " " << i;
      } else if (x / 100 % 10 == 3) {
        cout << " " << i;
      }
    }
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  nabeatsu(n);
  while (1) {
  }
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int i = 1, n;
  cin >> n;

  for (int k = 0; k < n; ++k) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else if (x % 10 == 3) {
      cout << " " << i;
    } else
      while (x /= 10) {
        if (x % 10 == 3 && i % 3 != 0) {
          cout << " " << i;
          break;
        }
      }

    ++i;
  }
  cout << endl;

  return 0;
}


Error: -11

Fixed submission:

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

void CHECK_NUM(int, int);
void INCLUDE3(int, int);
void END_CHECK_NUM(int, int);

int main() {
  int i = 1;
  int n;
  cin >> n;

  CHECK_NUM(i, n);

  return 0;
}

void CHECK_NUM(int x, int y) {
  if (x % 3 == 0) {
    cout << " " << x;
    END_CHECK_NUM(x, y);
  }
  INCLUDE3(x, y);
}

void INCLUDE3(int x, int y) {
  if (x % 10 == 3) {
    cout << " " << x;
    END_CHECK_NUM(x, y);
  }
  x /= 10;
  if (x)
    INCLUDE3(x, y);
  END_CHECK_NUM(x, y);
}

void END_CHECK_NUM(int x, int y) {
  if (++x <= y)
    CHECK_NUM(x, y);

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

#include <iostream>
using namespace std;

int main() {
  int n, i, x;
  cin >> n;

  for (i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      x = i;
      do {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x = x / 10;
      } while (x);
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int H, W;
  int i, j;

  do {
    cin >> H >> W;
    if ((H == 0) && (W == 0))
      break;
    for (i = 0; i < H; i++) {
      for (j = 0; j < W; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;

  } while (1);

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

#include <iostream>
using namespace std;

void CHECK_NUM(int, int);
void INCLUDE3(int, int, int);
void END_CHECK_NUM(int, int);

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

  CHECK_NUM(n, 1);

  return 0;
}

void CHECK_NUM(int n, int i) {
  int x = i;
  if (x % 3 == 0) {
    cout << " " << i;
    END_CHECK_NUM(n, i);
  }
  INCLUDE3(x, i, n);
}

void INCLUDE3(int x, int i, int n) {
  if (x % 10 == 3) {
    cout << " " << i;
    END_CHECK_NUM(n, i);
  }
  x /= 10;
  if (x) {
    INCLUDE3(x, i, n);
  }
  END_CHECK_NUM(n, i);
}

void END_CHECK_NUM(int n, int i) {
  if (++i <= n) {
    CHECK_NUM(n, i);
  }
  cout << endl;

  exit(EXIT_SUCCESS);
}


Error: 1

Fixed submission:

#include <iostream>
using namespace std;

void CHECK_NUM(int, int);
void INCLUDE3(int, int, int);
void END_CHECK_NUM(int, int);

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

  CHECK_NUM(n, 1);

  return 0;
}

void CHECK_NUM(int n, int i) {
  int x = i;
  if (x % 3 == 0) {
    cout << " " << i;
    END_CHECK_NUM(n, i);
  }
  INCLUDE3(x, i, n);
}

void INCLUDE3(int x, int i, int n) {
  if (x % 10 == 3) {
    cout << " " << i;
    END_CHECK_NUM(n, i);
  }
  x /= 10;
  if (x) {
    INCLUDE3(x, i, n);
  }
  END_CHECK_NUM(n, i);
}

void END_CHECK_NUM(int n, int i) {
  if (++i <= n) {
    CHECK_NUM(n, i);
  }
  cout << endl;

  exit(1);
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

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

bool has3(int x) {
  while (x) {
    if (x % 10 == 3)
      return true;
    x /= 10;
  }
  return false;
}

void call(int n) {
  for (int x = 1; x <= n; x++) {
    if (x % 3 == 0 || has3(x)) {
      cout << " " << x;
    }
  }
  cout << endl;
}

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

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {

    for (int x = i; x;) {
      if (x % 3 == 0) {
        cout << " " << i;
      } else if (x % 10 == 3) {
        cout << " " << i;
      } else if (x /= 10) {
        if (x % 10 == 3) {
          cout << " " << i;
        }
      }
    }

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

#include <iostream>
using namespace std;

int involve3(int a) {
  int flag = 0;
  int tmp = a;
  while (1) {
    if (tmp % 10 == 3) {
      flag = 1;
      break;
    }
    tmp = tmp / 10;
    if (tmp == 0)
      break;
  }
  return flag;
}

int main() {
  int num;
  int a = 3;
  cin >> num;
  while (1) {
    if (a > num)
      break;
    if (a % 3 == 0) {
      cout << " " << a;
    } else if (involve3(a) == 1) {
      cout << " " << a;
    }
    a += 1;
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int involve3(int a) {
  int flag = 0;
  int tmp = a;
  while (1) {
    if (tmp % 10 == 3) {
      flag = 1;
      break;
    }
    tmp = tmp / 10;
  }
  return flag;
}

int main() {
  int num = 60;
  int a = 3;
  int tmp;
  cin >> num;
  while (1) {
    if (a > num)
      break;
    if (a % 3 == 0) {
      cout << " " << a;
    } else if (involve3(a) == 1) {
      cout << " " << a;
    }
    a += 1;
  }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 10 == 3 || i / 10 % 10 == 3 || i / 100 % 10 == 3 ||
        i / 1000 % 10 == 3) {
      printf(" %d", i);
    }
  }
  printf("\\n");
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (x % 3 == 0 || x % 10 == 3) {
      printf(" %d", i);
    } else {
      while (true) {
        x /= 10;
        if (x % 10 == 3) {
          printf(" %d", i);
          break;
        }
      }
    }
  }
  printf("\\n");
  return 0;
}