Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	table := []int{0, 1, 2, 3, 5, 7, 8, 9}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		out := make([]int, 10)
		now := 0
		for n > 0 {
			out[now] = table[n%8]
			now++
			n /= 8
		}
		tmp := make([]string, 0)
		for i := now - 1; i >= 0; i-- {
			tmp = append(tmp, strconv.Itoa(out[i]))
		}
		fmt.Println(strings.Join(tmp, ""))
	}
}

C++: #include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;


long long int d8(long long int c, int n, int d)
{
	int r2 = n % 8;
	if (r2 > 4) r2++;
	if (r2 > 3) r2++;
	c += r2 * pow(10,d - 1);
	if (n / 8 > 0)
		c = d8(c, n / 8, d + 1);
	
	return c;
}

int main()
{
	int n;
	while (cin >> n && n != 0)
	{
		cout << d8(0, n, 1) << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
    string m = "01235789";
    for(int n;cin>>n,n;){
        string res = "";
        while(n){
            res.append(1, m[n%8]);
            n/=8;
        }
        reverse(res.begin(), res.end());
        cout << res << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;

int main()
{
    while(1)
    {
        long long n;
        cin>>n;if(!n)return 0;
        long long a=n+1;
        int k=-1;
        for(;a>0;++k){
            a/=8;
        }
        for(;k>=0;--k){
            int ans=n/pow(8,k);
            if(ans==4)cout<<5;
            else if(ans>4)cout<<ans+2;
            else cout<<ans;
            n=n%(long long)pow(8,k);
        }
        cout<<endl;
    }
    return 0;
}

C++: #include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int table[]={0,1,2,3,5,7,8,9};
int main(){
	int n;
	while(cin>>n,n){
		string ans="";
		while(n){
			ans +=table[n%8]+'0';
			n /=8;
		}
		reverse(ans.begin(), ans.end());
		cout <<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

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

ll hatisin(ll a) {
  ll res = 0;
  ll i = 1;
  int t = 0;
  while(a > 0) {
    t = a % 8;
    res += t * i;
    a /= 8;
    i *= 10;
  }
  return res;
}

ll fukkatu(ll b) {
  ll res = 0;
  ll i = 1;
  int t = 0;
  while(b > 0) {
    t = b % 10;
    res += V[t] * i;
    i *= 10;
    b /= 10;
  }
  return res;
}

int main() {
  ll res;
  while(true) {
    cin >> res;
    if (res == 0) break;
    cout << fukkatu(hatisin(res)) << endl;
  }
  
  return 0;
}

C++: #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]++;
			if (buf[i] == '4')buf[i]++;
		}
		printf("%s\n", buf);
	}
	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

string num = "01235789";

int main(){
    int n;
    while(cin >> n && n){
        string res = "";
        while(n > 0){
            res += num[n % 8];
            n /= 8;
        }
        cout << string(res.rbegin(), res.rend()) << endl;
    }
    return 0;
}

C++: #include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

const int MAX_N = 1000000009;
vector<int> ans;

bool ok(int a) {
    while(a) {
        if(a%10 == 4 || a%10 == 6) return false;
        a /= 10;
    }
    return true;
}
void init() {
    ans.reserve(MAX_N);
    rep(i,MAX_N) {
        if(!i) continue;
        if(ok(i)) ans.pb(i);
    }

}
int main() {
    init();
    int n;
    while(cin>>n) {
        if(!n) break;
        cout<<ans[n-1]<<endl;

    }
    return 0;
}

C++: #import<cstdio>
int t[]={0,1,2,3,5,7,8,9};
void s(int n){if(n>7)s(n/8);printf("%d",t[n%8]);}
main(){for(int a;scanf("%d",&a),a;puts(""))s(a);}

C++: #include <iostream>

using namespace std;

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

void solve(int);

int main() {

	int n;

	while(cin >> n) {
		if(!n) {
			break;
		}
		solve(n);
		cout << endl;
	}

	return 0;

}

void solve(int n) {

	if(n>=8) {
		solve(n/8);
	}

	cout << t[n%8];
	
}

C++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

int main(){
	const char oct[] = {'0','1','2','3','5','7','8','9'};
	ll n;
	while(~scanf("%lld",&n)){
		if(n==0) break;
		char buf[11];
		sprintf(buf,"%llo",n);

		for(int i=0;i<=10;i++){
			if(buf[i]=='\0') break;
			buf[i] = oct[buf[i]-'0'];
		}
		printf("%s\n",buf);
	}
}

C++: #include <cstdio>
#include <vector>
using namespace std;

int main() {
	vector<int> a;
	while(1) {
		int x = 0;
		scanf("%d", &x);
		a.push_back(x);
		if(x==0)break;
	}
	
	int l = a.size()-1;
	int b[l][10];
	
	for(int i=0;i<l;i++) {
		int a1 = a[i];
		for(int j=0;j<10;j++) {
			if(a1<1) {
				b[i][j] = -1;
			}else {
				int t = a1%8;
				if(t>3) {
					t++;
				}
				if(t>5) {
					t++;
				}
				b[i][j] = t;
				a1 /= 8;
			}
		}
	}
	
	for(int i=0;i<l;i++) {
		for(int j=9;j>=0;j--) {
			if(0<=b[i][j])printf("%d", b[i][j]);
		}
		if(i<l-1)printf("\n");
	}
	
	return 0;
}

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

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

void solve(int x) {
  if( x/8 > 0 ) solve( x/8 );
  cout << change[x%8];
}

int main()
{
  int n;
  while( cin >> n, n ) {
    solve( n );
    cout << endl;
  }
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<bitset>
typedef unsigned long ulong;

using namespace std;

string Oct(ulong n){
	string s;
	bitset<32> b(n);

	while( b.any() ){
		int c = (b[2]?1:0) * 4 + (b[1]?1:0) * 2 + (b[0]?1:0);
		s += (c + '0');
		b >>= 3;
	}
	reverse( s.begin(), s.end() );
	return s;
}
int main(){
	while(true){
		string sNum;
		ulong n;

		cin >> n;
		
		if( n == 0 )
			break;

		sNum = Oct(n);

		for(unsigned int i = 0; i < sNum.length(); ++i){
			switch( sNum[i] ){
				case '4':
					sNum[i] = '5';
					break;
				case '5':
				case '6':
				case '7':
					sNum[i] += 2;
					break;
			}
		}

		cout << sNum << '\n';
	}
	return 0;
}