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 <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 = 1e9+9;
vector<int> ans;

bool ok(int a) {
    while(a) {
        if(a%10 == 4 || a%10 == 6) return false;
        a /= 10;
    }
    return true;
}

int n;
string s[] = {"0", "1","2","3","5","7","8","9"};
void hoge() {
    ans.reserve(100000);
    rep(i,101) {
        if(!i) continue;
        if(ok(i)) ans.pb(i);
        // if(log10(i) == floor(log10(i))) 
    }
    cout<<endl;
    rep(i,ans.size()) {
        // if((i+1)%8==0)
        cout<<i+1<<" "<<ans[i]<<endl;
    }

}

int main() {

    while(cin>>n) {
        if(!n) break;
        string ans;
        while(n) {
            ans += s[n%8];
            n>>=3;
        }
        reverse(all(ans));
        cout<<ans<<endl;


    }

    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <string>
using namespace std;
const int INF=2<<20;
typedef long long int llf;
int main() {
	// your code goes here
	int num[8]={0,1,2,3,5,7,8,9};
	llf x=50,y,tx,ty,kx,ky,ans;
	llf n;
	while(cin >> n && n!=0){
		x=50;
		while(n/(llf)pow((llf)8,(llf)x)==0)
		x--;
		while(x!=-1){
			cout << num[(n%((llf)pow((llf)8,(llf)x+1)))/(llf)pow((llf)8,(llf)x)];
			x--;
		}
		cout << endl;
		
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;
const int INF = INT_MAX / 2;

typedef long long ll;

int main(){
	int N;
	while(cin >> N, N)
	{
		string ans;
		int w = 1;
		while(w < 1e9) w *= 8;
		while(w > 0)
		{
			ans.push_back('0' + N / w);
			N %= w;
			w /= 8;
		}
		bool flag = true;
		for(int i = 0; i < ans.size(); i++)
		{
			char out = ans[i];
			if(flag && out == '0') continue;
			flag = false;
			if(out >= '4') out++;
			if(out >= '6') out++;
			printf("%c", out);
		}puts("");
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

void func(int n)
{
	if(n >= 8)
	{
		func(n/8);
	}

	stringstream ss;
	ss << a[n%8];
	ans += ss.str();
}

int main()
{
	string s;
	while(cin >> s)
	{
		if(s == "0") break;

		ans = "";
		func(atoi(s.c_str()));

		cout << ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <sstream>

int main() {

    while (true) {
        int n;
        std::cin >> n;

        if (n == 0) {
            break;
        }

        std::stringstream ss;
        ss << std::oct << n;
        std::string n_oct = ss.str();

        const int len = n_oct.length();

        std::string s = n_oct;
        std::replace(s.begin(), s.end(), '7', '9');
        std::replace(s.begin(), s.end(), '6', '8');
        std::replace(s.begin(), s.end(), '5', '7');
        std::replace(s.begin(), s.end(), '4', '5');

        std::cout << s << std::endl;
    }

    return 0;

}

C++: #include<cstring>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int n;
while(1)
{
scanf("%d",&n);
if(n==0)break;

char ans[128];

sprintf(ans,"%o",n);
//printf("%s\n",ans);
for(int i=0;ans[i]!='\0';i++)
{
if(ans[i]>='4')ans[i]++;
if(ans[i]>='6')ans[i]++;
}
printf("%s\n",ans);
}
/*while(true)
{
cin>>n;
int ans=0;
for(int i=1;i<=n;i++)
	{
	
	if(i%10==4 || i/10==4)
		{
		//cout<<i<<endl;
		ans+=2;
		
		}
	else if(i%10==6 || i/10==6)
		{
		//cout<<i<<endl;
		ans+=2;
		
		}
	else ans++;

	}
	if(ans%10==4 || ans%10==6)ans++;
cout<<ans<<endl;
}*/
return 0;
}

C++: #include <cstdio>

void ToOctalNumber(int n){
	if(!n)return;
	ToOctalNumber(n >> 3);
	printf("%d",(n&7)<4?n&7:(n&7)==4?5:(n&7)+2);
}

int main(){
	int n;
	while(~scanf("%d",&n)){
		ToOctalNumber(n);
		puts("");
	}
}

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[100000000000];
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<sstream>
#include<algorithm>

using namespace std;

const string s = "01235789"

int main(){
  int n;
  while(cin >> n, n){
    stringstream ss;
    while(n){
      ss << s[n % 8];
      n /= 8;
    }
    string ans = ss.str();
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>


#define len 12
using namespace std;

char num[12];
int in;

int main () {

  while ( true ) {
    cin >> in;

    if ( in == 0 )
      break;

    for ( int i=11; i>=0; i-- ) {
      num[i] = in%8+'0';
      //num[i] = in%8+'0';
      in = in>>3;
    }
  
    int count = 0;
    while ( num[count] == '0' )
      count++;
  

    for ( int i=count;i <len; i++ ) {
      if ( num[i] == '4' )
	cout << '5';
      else if ( num[i] >'4' )
	cout << (char)(num[i]+2);
      else
	cout << num[i];
    }
    cout << endl;
  }

}

C++: // 2010/12/22 Tazoe

#include <iostream>
using namespace std;

void convert(int n)
{
	if(n==0)
		return;

	convert(n/8);

	switch(n%8){
		case 0:
			cout << 0;
			break;
		case 1:
			cout << 1;
			break;
		case 2:
			cout << 2;
			break;
		case 3:
			cout << 3;
			break;
		case 4:
			cout << 5;
			break;
		case 5:
			cout << 7;
			break;
		case 6:
			cout << 8;
			break;
		case 7:
			cout << 9;
			break;
	}
}

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		convert(n);
		cout << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int x[8] = { 0,1,2,3,5,7,8,9 };
int n, ok, k;
int main() {
	while (true) {
		ok = 0;
		cin >> n;
		if (!n) { break; }
		for (int i = 10; i >= 0; i++) {
			k = (n / (int)pow(8, i)) % 8;
			if (k > 0) { ok = 1; }
			if (ok == 1) { cout << x[k]; }
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include<math.h>

using namespace std;


int main(){
while(true){
    long ans=0;
    int c=0;
    int n;
    cin>>n;
    if(n==0)break;
    while(1){
        ans+=n%8*pow(10,c);
        n/=8;
        if(n==0)break;
        c++;
    }
    for(int i=0;i<=c;i++){
        int temp=((long)(ans/pow(10,i))%10);
        if(temp==4)ans+=pow(10,i);
        if(temp>=5)ans+=2*pow(10,i);
    }
    cout<<ans<<endl;
}
    return 0;
}