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

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {
  string S;
  cin >> S;
  for (int i = S.size(); i--;)
    cout << S[i];
  cout << endl;

  return 0;
}

int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}

Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
#define FOR(I, F, N) for (int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout << V << endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void) {
  string S;
  cin >> S;
  for (int i = S.size();; i--)
    cout << S[i];
  cout << endl;

  return 0;
}

int StrToInt(string s) {
  stringstream ss;
  ss << s;
  int val;
  ss >> val;
  return val;
}
string IntToStr(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}
Problem p00006 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main() {
  string str;
  cin >> str;
  int i = 0, j = str.size() - 1;
  while (i < j) {
    char tmp;
    tmp = str[i];
    str[i] = str[j];
    str[j] = tmp;
    ++i;
    --j;
  }
  cout << str << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string str;
  cin >> str;
  int i = 0, j = str.size() - 1;
  while (i < j) {
    char tmp;
    tmp = str[i];
    str[i] = str[j];
    str[j] = tmp;
  }
  cout << str << endl;
  return 0;
}
Problem p00006 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.size() <= 20) {
    for (int i = s.size(); i--;) {
      cout << s[i];
    }
    cout << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.size() <= 20) {
    for (int i = s.size();; i--) {
      cout << s[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00006 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  char str[21], reversed_str[21];
  scanf("%s", str);
  int len = strlen(str);

  int i;
  for (i = 0; i < len; ++i) {
    reversed_str[i] = str[len - 1 - i];
  }
  reversed_str[len] = '\\0';

  printf("%s\\n", reversed_str);

  return 0;
}

Error: 0

Fixed submission:

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

int main(void) {
  char str[20], reversed_str[20];
  scanf("%s", str);
  int len = strlen(str);

  int i;
  for (i = 0; i < len; ++i) {
    reversed_str[i] = str[len - 1 - i];
  }
  reversed_str[len] = '\\0';

  printf("%s\\n", reversed_str);

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

#include <stdio.h>

int main(void) {

  char a[21], b[21] = {'0'};
  int s, t;

  scanf("%s", a);

  for (s = 0; a[s] != '\\0'; s++) {
  }

  for (t = 0; a[t] != '\\0'; t++) {

    b[s - t - 1] = a[t];
  }

  printf("%s\\n", b);

  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main() {

  char a[25], b[25] = {'0'};
  int s, t;

  scanf("%s", &a);

  for (s = 0; a[s] != '\\0'; s++)

    for (t = 0; a[t] != '\\0'; t++) {

      b[s - t] = a[t];
    }

  printf("%s", b);

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

#include <iostream>
using namespace std;
int main() {
  string str;
  cin >> str;
  int n = str.size();
  for (int i = n - 1; i >= 0; i--) {
    cout << str[i];
  }
  cout << endl;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  string str;
  cin >> str;
  int n = str.size();
  for (int i = n - 1; i >= 0; i++) {
    cout << str[i];
  }
  cout << endl;
}
Problem p00006 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
void sort(char *str) {
  int len, len2 = 0;
  char work;
  len = strlen(str);

  for (len = len - 1; len > len2; len--, len2++) {
    work = str[len];
    str[len] = str[len2];
    str[len2] = work;
  }
}

int main() {
  char str[21];

  cin >> str;
  sort(str);
  cout << str << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

void sort(char *str) {
  int len, len2 = 0;
  char work;
  len = strlen(str);

  for (len = len - 1; len > len2; len--, len2++) {
    work = str[len];
    str[len] = str[len2];
    str[len2] = work;
  }
}

int main() {
  char str[20];
  cin >> str;
  sort(str);
  cout << str << endl;
  return 0;
}
Problem p00006 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string str;
  cin >> str;
  for (size_t i = str.size() - 1; i >= 0; --i) {
    if (i == -1)
      break;
    cout << str[i];
  }
  cout << endl;
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  string str;
  cin >> str;
  for (size_t i = str.size() - 1; i >= 0; --i) {
    cout << str[i];
  }
  cout << endl;
  return 0;
}
Problem p00006 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int gcd(int, int);

int main() {
  char str[21];

  scanf("%s", str);
  for (int i = strlen(str) - 1; 0 <= i; i--) {
    putchar(str[i]);
  }
  putchar('\\n');

  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <stack>

using namespace std;

int main() {
  char str[22];
  stack<char> stk;

  fgets(str, sizeof(str) - 1, stdin);

  for (int i = 0; str[i] != '\\n'; i++) {
    stk.push(str[i]);
  }

  while (!stk.empty()) {
    putchar(stk.top());
    stk.pop();
  }

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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
int main() {
  string x;
  int i;
  cin >> x;
  for (i = x.size(); i--;) {
    cout << x[i];
  }
  cout << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string.h>
using namespace std;
int main() {
  string x;
  int i;
  cin >> x;
  for (i = x.size();; i--) {
    cout << x[i];
  }
  cout << endl;
  return 0;
}
Problem p00006 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main(void) {
  string str;
  cin >> str;
  int l = str.size();
  for (int i = l; i > 0; i--) {
    cout << str[i - 1];
  }
  cout << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  string str;
  cin >> str;
  int l = str.size();
  for (int i = l; i >= 0; i++) {
    cout << str[i];
  }
  cout << endl;
  return 0;
}
Problem p00006 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  char str[21];
  scanf("%s", str);
  int len = strlen(str);
  for (int i = len - 1; i >= 0; i--) {
    printf("%c", str[i]);
  }
  printf("\\n");
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  char str[20];
  scanf("%s", str);
  int len = strlen(str);
  for (int i = len - 1; i >= 0; i--) {
    printf("%c", str[i]);
  }
  printf("\\n");
  return 0;
}
Problem p00006 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int i = 0, j = 0, k = 0, l = 0;
  char str[20 + 10], str2[20 + 10];
  scanf("%s", str);
  while (str[j] != '\\0') {
    j++;
  }
  while (k < j) {
    str2[k] = str[j - k - 1];
    k++;
  }
  str2[k] = '\\0';
  printf("%s\\n", str2);
}

Error: TLE

Fixed submission:

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

int main() {
  char str[100];
  int len;
  while (scanf("%s", str)) {
    len = strlen(str);
    reverse(str, str + len);
    printf("%s\\n", str);
  }
  return 0;
}
Problem p00006 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main(void);
std::string rev_string(std::string str);

int main() {
  std::string str = "";
  // char str[20];
  std::cin >> str;
  std::cout << rev_string(str) << std::endl;

  // while (1);
  return 0;
}

//*
std::string rev_string(std::string str) {
  int i;
  int len = str.length();
  for (i = 0; i < len / 2; i++) {
    char temp = str[i];
    str[i] = str[len - i - 1];
    str[len - i - 1] = temp;
  }

  return str;
}
//*/


Error: TLE

Fixed submission:

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

int main(void);
std::string rev_string(std::string str);

int main() {
  std::string str = "";
  // char str[20];
  std::cin >> str;
  std::cout << rev_string(str) << std::endl;

  while (1)
    ;
  return 0;
}

//*
std::string rev_string(std::string str) {
  int i;
  int len = str.length();
  for (i = 0; i < len / 2; i++) {
    char temp = str[i];
    str[i] = str[len - i - 1];
    str[len - i - 1] = temp;
  }

  return str;
}
//*/
Problem p00006 (C++) — buggy submission, verdict: Runtime Error

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char in[21], out[21];
  cin >> in;
  int len = strlen(in);
  for (int i = 0; i < len; i++) {
    out[len - i - 1] = in[i];
  }
  out[len] = 0;
  cout << out << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char in[20], out[20];
  cin >> in;
  int len = strlen(in);
  for (int i = 0; i < len; i++) {
    out[len - i - 1] = in[i];
  }
  out[len] = 0;
  cout << out << endl;
  return 0;
}
Problem p00006 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  string s;

  cin >> s;

  for (int i = s.size() - 1; i >= 0; --i)
    cout << s[i];

  cout << endl;
}


Error: -11

Fixed submission:

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

int main() {

  string s;

  cin >> s;

  for (int i = s.size() - 1; i >= 0; ++i)
    cout << s[i];

  cout << endl;
}
Problem p00006 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>

using namespace std;

int main() {
  string str;
  cin >> str;
  for (int i = str.size() - 1; i >= 0; i--)
    cout << str[i];
  cout << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string str;
  cin >> str;
  for (int i = str.size() - 1; i >= 0; i++)
    cout << str[i];
  cout << endl;
  return 0;
}
Problem p00006 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>
int main() {
  char a[100];
  scanf("%s", &a);
  for (int i = strlen(a) - 1; i >= 0; i--) {
    printf("%c", a[i]);
  }
  printf("\\n");
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
#include <string.h>
int main() {
  char a[20];
  scanf("%s", &a);
  for (int i = strlen(a) - 1; i >= 0; i--) {
    printf("%c", a[i]);
  }
  return 0;
}
Problem p00018 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int comp(int *a, int *b) {
  int buffer;
  if (*a > *b) {
    buffer = *b;
    *b = *a;
    *a = buffer;
    return 1;
  } else {
    return 0;
  }
}

int main() {
  int a, b, c, d, e;
  int i = 1;
  cin >> a >> b >> c >> d >> e;
  while (i) {
    i = 0;
    i += comp(&a, &b);
    i += comp(&b, &c);
    i += comp(&c, &d);
    i += comp(&d, &e);
  }
  cout << e << " " << d << " " << c << " " << b << " " << a << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int comp(int a, int b) {
  int buffer;
  if (a > b) {
    b = buffer;
    b = a;
    a = buffer;
    return 1;
  } else {
    return 0;
  }
}

int main() {
  int k[5];
  cin >> k[0] >> k[1] >> k[2] >> k[3] >> k[4];
  while (comp(k[0], k[1]) || comp(k[1], k[2]) || comp(k[2], k[3]) ||
         comp(k[3], k[4])) {
  }
  cout << k[4] << " " << k[3] << " " << k[2] << " " << k[1] << " " << k[0]
       << endl;
  return 0;
}
Problem p00018 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a[5];
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }
  sort(a, a + 5);
  reverse(a, a + 5);
  cout << a[0];
  for (int j = 1; j < 5; j++) {
    cout << " " << a[j];
  }
  cout << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int a[5];
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }
  sort(a, a + 5);
  for (int j = 4; j >= 0; j++) {
    if (j == 0)
      cout << a[0] << endl;
    else
      cout << a[j] << " ";
  }
  return 0;
}
Problem p00018 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <stdio.h>
using namespace std;
long long int a[5];
int main() {
  int i;
  for (i = 0; i < 5; i++) {
    scanf("%lld ", &a[i]);
  }
  sort(a, a + 5);
  for (i = 4; i >= 0; i--) {
    if (i != 0)
      printf("%lld ", a[i]);
    else {
      printf("%lld\\n", a[i]);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:


#include <stdio.h>

int Counting_sort(int A[], int k, int n) {
  int i = 0, j = 0;
  int B[15], C[100];
  for (i = 0; i <= k; i++)
    C[i] = 0;
  for (j = 1; j <= 5; j++)
    C[A[j]] = C[A[j]] + 1;
  for (i = 1; i <= k; i++)
    C[i] = C[i] + C[i - 1];
  for (j = n; j >= 1; j--) {
    B[C[A[j]]] = A[j];
    C[A[j]] = C[A[j]] - 1;
  }

  for (i = 5; i >= 1; i--) {
    if (i == 1)
      printf("%d\\n", B[i]);
    else
      printf("%d ", B[i]);
  }
}

int main() {
  int n = 0, i = 0, k = 0, A[15] = {0};
  while (1) {

    for (i = 1; i <= 5; i++) {
      scanf("%d", &A[i]);
      if (A[i] > k) {
        k = A[i];
      }
    }
    Counting_sort(A, k, 5);
  }
  return 0;
}
Problem p00018 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> a;
  int ptr = 0;
  int tmp;
  while (cin >> tmp)
    a.push_back(tmp);
  stable_sort(a.begin(), a.end(), greater<int>());
  for (int i = 0; i < a.size(); ++i)
    cout << a[i] << (i == a.size() - 1 ? "" : " ");
  cout << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> a;
  int ptr = 0;
  while (cin >> a[ptr++])
    ;
  stable_sort(a.begin(), a.end());
  for (int i = 0; i < a.size(); ++i)
    cout << a[i] << " ";
  cout << endl;
  return 0;
}
Problem p00018 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int in[5];
  for (int i = 0; i < 5; i++)
    cin >> in[i];
  sort(in, in + 5, greater<int>());
  for (int i = 0; i < 4; i++)
    cout << in[i] << " ";
  cout << in[4] << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int num[5];

  for (int i = 0; i = 4; i++)
    cin >> num[i];

  sort(num, num + 5);

  for (int i = 4; i = 1; i--)
    cout << num[i] << " ";

  cout << num[0] << "\\n";
}
Problem p00018 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>

using namespace std;

int main() {
  int num[5];
  for (int i = 0; i < 5; i++) {
    scanf("%d", num + i);
  }
  sort(num, num + 5, greater<int>());

  for (int i = 0; i < 5; i++) {
    printf("%d%s", num[i], i == 4 ? "\\n" : " ");
  }
  return 0;
}

Error: -11

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>

using namespace std;

int main() {
  string str;
  int num[5];
  for (int i = 0; i < 5; i++) {
    scanf("%d", num + i);
  }
  sort(num, num + 5, greater<int>());

  for (int i = 0; i < 5; i++) {
    printf("%d%s", num[i], i == 4 ? '\\n' : ' ');
  }
  return 0;
}
Problem p00018 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n[5];

  for (int i = 0; i < 5; i++) {
    cin >> n[i];
  }
  sort(n, n + 5);

  cout << n[4] << " " << n[3] << " " << n[2] << " " << n[1] << " " << n[0]
       << endl;
}

Error: -11

Fixed submission:

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

int main() {
  int n[5];

  for (int i = 0; i < 5; i++)
    cin >> n[i];
  sort(n, n + 5);
  for (int i = 4; i >= 0; i++) {
    cout << n[i];
    if (i != 0)
      cout << " ";
  }
  cout << endl;
}
Problem p00018 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  vector<int> Number(5);
  for (int i = 0; i < 5; i++) {
    scanf("%d", &Number[i]);
  }
  sort(Number.begin(), Number.end(), greater<int>());
  for (int i = 0; i < 5; i++) {
    if (i != 4) {
      printf("%d ", Number[i]);
    } else {
      printf("%d\\n", Number[i]);
    }
  }
  return 0;
}

Error: -11

Fixed submission:

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

int main() {
  int n;
  scanf("%d", n);
  int Fraction = 1;
  for (int i = 0; i < n; i++) {
    Fraction *= n - i;
  }
  printf("%d\\n", Fraction);
  return 0;
}
Problem p00018 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main(int argc, char const *argv[]) {
  int target[5];

  cin >> target[0] >> target[1] >> target[2] >> target[3] >> target[4];

  sort(target, target + 5, greater<int>());

  for (int i = 0; i < 5; i++) {
    cout << (i == 0 ? "" : " ") << target[i];
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main(int argc, char const *argv[]) {
  int target[5];

  while (1) {
    cin >> target[0] >> target[1] >> target[2] >> target[3] >> target[4];

    sort(target, target + 5, greater<int>());

    for (int i = 0; i < 5; i++) {
      cout << (i == 0 ? "" : " ") << target[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00208 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0208

int d[] = {0, 1, 2, 3, 5, 7, 8, 9};

int div(int n) {
  if (n >= 8)
    div(n / 8);
  cout << d[n % 8];
}

int main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    div(n);
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0208

bool hated(int x) {
  while (x > 0) {
    if (x % 10 == 4 || x % 10 == 6)
      return true;
    x /= 10;
  }
  return false;
}

int main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    int ans = 1;
    for (int i = 0; i < n - 1; i++) {
      ans++;
      while (hated(ans))
        ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00208 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<char, int> P;

char buf[11];
int main() {
  int n;
  while (scanf("%d", &n), n) {
    sprintf(buf, "%o", n);
    rep(i, strlen(buf)) {
      if (buf[i] >= '5')
        buf[i] += 2;
      if (buf[i] == '4')
        buf[i]++;
    }
    printf("%s\\n", buf);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<char, int> P;

char buf[1000000];
int main() {
  int n;
  while (scanf("%d", &n), n) {
    sprintf(buf, "%o", n);
    for (char &c : buf) {
      if (c >= '5')
        c += 2;
      if (c == '4')
        c++;
    }
    printf("%s\\n", buf);
  }
  return 0;
}
Problem p00208 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main() {
  int n;
  char *p, s[32];
  while (scanf("%d", &n), n) {
    sprintf(s, "%o", n);
    for (p = s; *p; ++p)
      if (*p > '4')
        *p += 2;
      else if (*p > '3')
        *p += 1;
    puts(s);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int f(long long n) {
  while (n) {
    if (n % 10 == 4 || n % 10 == 6)
      return 0;
    n /= 10;
  }
  return 1;
}
int main() {
  long long n, c, i;
  while (scanf("%lld", &n), n) {
    for (c = i = 0; c < n;) {
      ++i;
      if (f(i))
        ++c;
    }
    printf("%lld\\n", i);
  }
  return 0;
}