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

#include <stdio.h>
int main() {
  int H, W;
  int i, j;
  for (;;) {
    scanf("%d %d", &H, &W);
    if (H != 0 && W != 0) {
      for (i = 1; i <= H; i++) {
        for (j = 1; j <= W; j++) {
          if (i % 2 == 1 && j % 2 == 1 || i % 2 == 0 && j % 2 == 0) {
            printf("#");
          } else if (i % 2 == 1 && j % 2 == 0 || i % 2 == 0 && j % 2 == 1) {
            printf(".");
          }
        }
        printf("\\n");
      }
      printf("\\n");
    } else {
      break;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int H, W;
  int i, j;
  for (;;) {
    scanf("%d %d", &H, &W);
    for (i = 1; i <= H; i++) {
      for (j = 1; j <= W; j++) {
        if (i % 2 == 1 && j % 2 == 1 || i % 2 == 0 && j % 2 == 0) {
          printf("#");
        } else if (i % 2 == 1 && j % 2 == 0 || i % 2 == 0 && j % 2 == 1) {
          printf(".");
        }
      }
      printf("\\n");
    }
    printf("\\n");
  }
  return 0;
}
Problem p02405 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int h, w;
  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0)
      break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (i % 2 == 0 && j % 2 == 0 || i % 2 == 1 && j % 2 == 1) {
          cout << "#";
        } else {
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
void output() {
  int H, W;
  cin >> H >> W;
  while (1) {
    if (H == 0 && W == 0)
      break;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if ((i + j) % 2 == 0) {
          cout << "#";
        } else {
          cout << ".";
        }
      }
      cout << "\\n";
    }
    cout << endl;
  }
}
int main() {
  output();
  return 0;
}
Problem p02405 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int H, W, x, y;
  string a[300];
  string b[300];
  for (int i = 0; i < 150; i++) {
    a[i * 2] = "#";
    a[i * 2 + 1] = ".";
    b[i * 2] = ".";
    b[i * 2 + 1] = "#";
  }
  cin >> H >> W;
  while (!(H == 0 && W == 0)) {
    x = H % 2;
    y = (H - x) / 2;
    for (int j = 0; j < y; j++) {
      for (int k = 0; k < W; k++) {
        cout << a[k];
      }
      cout << endl;
      for (int l = 0; l < W; l++) {
        cout << b[l];
      }
      cout << endl;
    }
    if (H % 2 == 1) {
      for (int m = 0; m < W; m++) {
        cout << a[m];
      }
      cout << endl;
    }
    cout << endl;
    cin >> H >> W;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int H, W, x;
  string a[300];
  string b[300];
  for (int i = 0; i < 150; i++) {
    a[i * 2] = "#";
    a[i * 2 + 1] = ".";
    b[i * 2] = ".";
    b[i * 2 + 1] = "#";
  }
  a[300] = "#";
  b[300] = ".";
  cin >> H >> W;
  while (!(H == 0 && W == 0)) {
    x = H / 2;
    for (int j = 0; j < x; j++) {
      for (int k = 0; k < W; k++) {
        cout << a[k];
      }
      cout << "\\n";
      for (int l = 0; l < W; l++) {
        cout << b[l];
      }
      cout << "\\n";
    }
    if (W % 2 == 1) {
      for (int m = 0; m < W; m++) {
        cout << a[m];
      }
      cout << "\\n";
      cin >> H >> W;
    }
  }
  return 0;
}
Problem p02405 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {

  for (int x = 0; true; x++) {
    int h, w;
    cin >> h >> w;

    if (h == 0 && w == 0)
      break;

    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        if ((i + j) % 2 == 0) {
          cout << "#";
        } else {
          cout << ".";
        }

        if (j == w) {
          cout << endl;
        }
      }
      if (i == h) {
        cout << endl;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {

  for (int x = 0; true; x++) {
    int h, w;
    cin >> h >> w;

    for (int i = 1; i <= h; i++) {
      for (int j = 1; j <= w; j++) {
        if ((i + j) % 2 == 0) {
          cout << "#";
        } else {
          cout << ".";
        }

        if (j == w) {
          cout << endl;
        }
      }
      if (i == h) {
        cout << endl;
      }
    }
  }

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

#define _USE_MATH_DEFINES
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x = i / 10;
    int y = i / 100;
    int z = i / 1000;
    int w = i / 10000;
    int v = i / 100000;
    if (i % 3 == 0) {
      cout << " " << i;
    } else if (i % 10 == 3) {
      cout << " " << i;
    } else if (x % 10 == 3) {
      cout << " " << i;
    } else if (y % 10 == 3) {
      cout << " " << i;
    } else if (z % 10 == 3) {
      cout << " " << i;
    } else if (w % 10 == 3) {
      cout << " " << i;
    } else if (v % 10 == 3) {
      cout << " " << i;
    }
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
int main() {
  while (true) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      if (i % 3 == 0 || i % 10 == 3) {
        cout << " " << i;
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a = 1, b, c, count = 0;
  cin >> b;
  for (; count < b; count++) {
    if (a % 3 == 0 || a % 10 == 3) {
      cout << ' ' << a;
    } else {
      for (c = a; c != 0;) {
        c /= 10;
        if (c % 10 == 3) {
          cout << ' ' << a;
          break;
        }
      }
    }
    a++;
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a = 1, b, c, count = 0;
  cin >> b;
  for (; count < b; count++) {
    if (a % 3 == 0 || a % 10 == 3) {
      cout << ' ' << a;
    } else {
      for (c = 1; c != 0;) {
        c = a / 10;
        if (c % 10 == 3) {
          cout << ' ' << a;
          break;
        }
      }
    }
    a++;
  }
  cout << endl;
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  double pai = 3.141592653589;
  int n;
  scanf("%d", &n);
  for (int i = 3; i <= n; i++) {
    int x = i;
    if (i % 3 == 0) {
      printf(" %d", i);
    } else {
      do {
        if (x % 10 == 3) {
          printf(" %d", i);
          break;
        }
        x /= 10;
      } while (x);
    }
  }
  printf("\\n");
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  double pai = 3.141592653589;
  int h, w;
  for (;;) {
    scanf("%d %d", &h, &w);
    if (h == 0 && w == 0)
      break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        printf("#");
      }
      printf("\\n");
    }
    printf("\\n");
  }
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

void call(int n);

void call(int n) {
  int x;
  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);
    }
  }
  cout << endl;
}

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

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

void call(int n);

void call(int n) {
  int x;
  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);
    }
  }
  cout << endl;
}

int main(void) {
  int n;
  cin >> n;
  call(n);
}
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++) {
    if (i % 3 == 0) {
      std::cout << " " << i;
      continue;
    } else if (i % 10 == 3) {
      std::cout << " " << i;
      continue;
    }

    int a = i / 10;
    if (a % 10 == 3) {
      std::cout << " " << i;
      continue;
    }

    int b = a / 10;
    if (b % 10 == 3) {
      std::cout << " " << i;
      continue;
    }

    int c = b / 10;
    if (c % 10 == 3) {
      std::cout << " " << i;
      continue;
    }
  }

  std::cout << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int main() {
  while (1) {
    int H, W;
    std::cin >> H >> W;

    if (H == 0 && W == 0) {
      break;
    }

    for (int j = 0; j < H; j++) {
      for (int i = 0; i < W; i++) {
        if ((i + j) % 2 == 0) {
          std::cout << "#";
        } else {
          std::cout << ".";
        }

        if (i == W - 1) {
          std::cout << std::endl;
        }
      }
    }

    std::cout << std::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;
      continue;
    } else if (i % 10 == 3) {
      cout << " " << i;
      continue;
    }

    int a = i;
    a /= 10;
    if (a % 10 == 3) {
      cout << " " << i;
      continue;
    }
    a /= 10;
    if (a % 10 == 3) {
      cout << " " << i;
      continue;
    }
    a /= 10;
    if (a % 10 == 3) {
      cout << " " << i;
      continue;
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:


#include <iostream>
using namespace std;

void call(int n);

int main() {

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

    int a = i;
    int C = 0;
    do {
      a /= 10;
      if (a % 10 == 3) {
        cout << " " << i;
        C = 1;
      }
    } while (C);
  }
  cout << endl;

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

#include <iostream>
using namespace std;

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

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

#include <bits/stdc++.h>
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 <bits/stdc++.h>
using namespace std;

void call(int n) {
  for (int i = 1; i <= n; ++i) {
    int x = 1;
    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;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, a, b, c, d;
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    int x[i];
    int a = i % 3;
    int b = i % 10;
    int c = i / 10;
    x[i] = 0;
    while (c > 2) {
      int d = c % 10;
      if (d == 3) {
        x[i] = 3; /* code */
      }
      c = c / 10;
    }
    if (a == 0 || b == 3 || x[i] == 3) {
      cout << " " << i;
    }
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int a, b;

  do {
    cin >> a >> b;
    if (a != 0 || b != 0) {
      for (int i = 1; i < a + 1; i++) {
        int x = i % 2;
        if (x == 1) {
          for (int j = 1; j < b + 1; j++) {
            int y = j % 2;
            if (y == 1) {
              cout << "#";
            } else {
              cout << ".";
            }
          }
          cout << "\\n";

        } else {
          for (int j = 1; j < b + 1; j++) {
            int y = j % 2;
            if (y == 1) {
              cout << ".";
            } else {
              cout << "#";
            }
          }
          cout << "\\n";
        }
      }
    } else
      break;
    cout << "\\n";
  } while (a != 0 || b != 0);

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

#include <iostream>

using namespace std;

bool isDivisible3(int n) { return n % 3 == 0; }

bool includes3(int n) {
  if (n % 10 == 3) {
    return true;
  } else {
    n /= 10;
    if (n) {
      return includes3(n);
    }
    return false;
  }
}

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

  for (int i = 1; i <= n; ++i) {
    if (isDivisible3(i) || includes3(i)) {
      cout << ' ' << i;
    }
  }

  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>

using namespace std;

void solve() {
  int H, W;
  while (cin >> H >> W, H || W) {
    for (int i = 0; i < H; ++i) {
      for (int j = 0; j < W; ++j) {
        if ((i + j) % 2) {
          cout << ".";
        } else {
          cout << "#";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
}

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

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

  for (int i = 1; i <= n; 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;
    }
  }
  cout << endl;
}


Error: TLE

Fixed submission:

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

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

    if (i % 3 == 0) {
      cout << " " << i;
    } else if (i % 10 == 3) {
      cout << " " << i;
    } else if ((i /= 10) % 10 == 3) {
      cout << " " << i;
    }
  }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#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); // your code goes here
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

bool has3(int x) {
  while (1) {
    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); // your code goes here
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    bool flag = i % 3 == 0;
    stringstream ss;
    ss << i;
    string s = ss.str();
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == '3')
        flag = true;
    }
    if (flag)
      cout << " " << i;
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
int main() {
  while (true) {
    int n;
    stringstream ss;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      bool flag = i % 3 == 0;
      ss << i;
      string s = ss.str();
      for (int j = 0; j < s.size(); j++) {
        if (s[j] == '3')
          flag = true;
      }
      if (flag)
        cout << " " << i;
    }
    cout << endl;
  }
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int x;
  cin >> x;
  for (int i = 1; i <= x; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
      continue;
    }
    int y = i;
    while (y) {
      if (y % 10 == 3) {
        cout << " " << i;
        break;
      }
      y /= 10;
    }
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int x;
  cin >> x;
  for (int i = 1; i <= x; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
      continue;
    }
    while (i) {
      if (i % 10 == 3) {
        cout << " " << i;
      }
      i /= 10;
    }
  }
  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 {
      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() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else if (x % 10 == 3) {
      cout << " " << i;
    } else {
      int d = (x / 10);
      while (d) {
        if (d % 10 == 3) {
          cout << " " << i;
        } else {
          d /= 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 (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;
        }
        x = x / 10;
      }
    }
  }
  cout << endl;
  return 0;
}


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 if (i % 10 == 3) {
      cout << " " << i;
    }
    i /= 10;
  }
  cout << endl;
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int n;
  int i;

  scanf("%d", &n);

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

Error: -11

Fixed submission:

#include <stdio.h>

int main() {
  int n;
  int i;

  scanf("%d", n);

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

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

void call(int n) {
  int i = 1;
  int x = i;

  while (1) {
    if (x % 3 == 0) {
      CO " " << i;
    } else {
      if (x % 10 == 3) {
        CO " " << i;
      } else {
        while (1) {
          x /= 10;
          if (x % 10 == 3) {
            CO " " << i;
            break;
          }
          if (x == 0)
            break;
        }
      }
    }
    ++i;
    x = i;
    if (i > n)
      break;
  }
}

int main(void) {
  int n = 0;
  CI n;

  call(n);

  CO endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

void call(int n) {
  int i = 1;
  int x = i;

  while (1) {
    if (x % 3 == 0) {
      CO " " << i;
    } else {
      if (x % 10 == 3) {
        CO " " << i;
      }
      while (1) {
        x /= 10;
        if (x % 10 == 3) {
          CO " " << i;
          break;
        }
        if (x)
          break;
      }
    }
    ++i;
    x = i;
    if (i > n)
      break;
  }
}

int main(void) {
  int n = 0;
  CI n;

  call(n);

  CO endl;
}
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++) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      while (x != 0) {
        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 || i % 10 == 3) {
      cout << " " << i;
    } else {
      while (i % 10 != 3 && i > 0) {
        i = i / 10;
        if (i % 10 == 3) {
          cout << " " << i;
        }
      }
    }
  }
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded


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

  int i, j, n;
  scanf("%d", &n);

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

    if (i % 3 == 0) {
      printf(" %d", i);
      continue;
    }
    j = i;

    while (1) {
      if (j % 10 == 3) {
        printf(" %d", i);
        break;
      }
      j /= 10;
      if (j == 0)
        break;
    }
  }

  printf("\\n");

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int n, m, l;

  scanf("%d", &n);

  for (m = 3; m <= n; ++m) {
    if (m % 3 == 0) {
      printf(" %d", m);
    } else {
      l = n;
      while (1) {
        if (l == 0)
          break;

        if (l % 10 == 3) {
          printf(" %d", m);
        } else {
          l /= 10;
        }
      }
    }
  }
  printf("\\n");

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

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

int main() {

  int n;
  cin >> n;

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

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {

  int n;

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

  return 0;
}